jquery api :animated Selector

来源:互联网 发布:bp神经网络算法实现 编辑:程序博客网 时间:2024/05/20 23:57

:animated Selector

描述: 选择所有正在执行动画效果的元素.

jQuery(":animated")

注意:  如果您使用一个自定义的jQuery绑定一个没有效果模块:animated选择器会抛出一个错误。

Additional Notes:(其他注意事项:)

  • 因为:animated 是一个 jQuery 延伸出来的选择器,并不是的CSS规范的一部分,使用:animated 查询不能充分利用原生DOM提供的querySelectorAll() 方法来提高性能。为了当使用:animated 的时候在现代浏览器上获得更佳的性能,首先使用纯CSS选择器选择元素,然后使用.filter(":animated").

例子:

改变正在执行动画的 div 的颜色。

<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title><script src="jquery-1.10.2.js"></script><style>div{ background:#FF0; border:1px solid #AAA; width:80px; height:80px; margin:0 5px; float:left}div.colored{ background:#0F0;}</style></head><body><button id="run">运行</button><div></div><div id="mover"></div><div></div><script>$("#run").click(function(){$("div:animated").toggleClass("colored");});function animateIt(){$("#mover").slideToggle("slow",animateIt);}animateIt();</script></body></html>

效果图:


0 0
原创粉丝点击