gpt4 book ai didi

javascript - 用 angular.element(element).offset 替换 $(element).offset

转载 作者:行者123 更新时间:2023-11-29 23:56:20 32 4
gpt4 key购买 nike

我不应该在我的应用程序中使用 jQuery,但我有一个场景,我需要元素的偏移量,而不是使用 $(element).offset()

我已经使用了 angular.element(element).offset() 并且我正在使用像 angular.element(element).animate(targetPosition) 这样的动画工作正常,所以我想知道 angular.element() 是否内置了所有 jQuery 函数?

如有任何解释,我们将不胜感激。

最佳答案

如果我必须表达我的想法,那么:

Angular 确实有一些重要的 jquery 方法,但有一些限制,Angular 团队将其命名为 jqLit​​e。

Full doc for angular.element .

这只是一种情况,当您的页面中没有 jquery 时,angular 将使用 jqLit​​e,如果您在 angular 之前加载 jQuery,那么整个 jQuery 方法都可以使用。在这种情况下,将使用 jQuery 方法而不是 jqLit​​e。


来自文档:

Angular's jqLite

jqLite provides only the following jQuery methods:

addClass() - Does not support a function as first argument
after()
append()
attr() - Does not support functions as parameters
bind() (deprecated, use on()) - Does not support namespaces, selectors or eventData
children() - Does not support selectors
clone()
contents()
css() - Only retrieves inline-styles, does not call getComputedStyle(). As a setter, does not convert numbers to strings or append 'px', and also does not have automatic property prefixing.
data()
detach()
empty()
eq()
find() - Limited to lookups by tag name
hasClass()
html()
next() - Does not support selectors
on() - Does not support namespaces, selectors or eventData
off() - Does not support namespaces, selectors or event object as parameter
one() - Does not support namespaces or selectors
parent() - Does not support selectors
prepend()
prop()
ready() (deprecated, use angular.element(callback) instead of angular.element(document).ready(callback))
remove()
removeAttr() - Does not support multiple attributes
removeClass() - Does not support a function as first argument
removeData()
replaceWith()
text()
toggleClass() - Does not support a function as first argument
triggerHandler() - Passes a dummy event object to handlers
unbind() (deprecated, use off()) - Does not support namespaces or event object as parameter
val()
wrap()

关于javascript - 用 angular.element(element).offset 替换 $(element).offset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41548371/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com