本文实例讲述了jQuery中:animated选择器用法。分享给大家供大家参考。具体分析如下:
此选择器匹配所有正在执行动画效果的元素。
可以使用animate()方法创建自定义动画。
语法结构:
$(\":animated\")
此选择器一般也要和其他选择器配合使用,比如类选择器和元素选择器等等。例如:
$(\"li:animated\").css(\"background-color\",\"blue\")
以上代码能够将正在执行动画下过的li元素的背景颜色设置为蓝色。
如果不和其他选择器配合使用,则默认状态是和*选择器配合使用,例如$(\":animated\")等同于$(\"*:animated\")。
实例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset=\" utf-8\">
<meta name=\"author\" content=\"http://www.phpstudy.net/\" />
<title>phpstudy</title>
<style type=\"text/css\">
li{
list-style-type:none;
width:150px;
height:30px;
}
.run{background-color:green;}
.static{background-color:#603;}
</style>
<script type=\"text/javascript\" src=\"mytest/jQuery/jquery-1.8.3.js\"></script>
<script type=\"text/javascript\">
$(document).ready(function(){
function runit(){
$(\".run\").animate({width:\"250px\"});
$(\".run\").animate({width:\"150px\"},runit);
}
$(\"button\").click(function(){
runit();
$(\"li:animated\").css(\"background-color\",\"blue\");
})
})
</script>
</head>
<body>
<ul>
<li class=\"run\"></li>
<li class=\"static\"></li>
</ul>
<button>点击开始动画</button>
</body>
</html>
以上可以将动画元素的背景颜色设置为蓝色。
希望本文所述对大家的jQuery程序设计有所帮助。
本文地址:https://www.stayed.cn/item/13208
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我