jQuery中:animated选择器用法实例


本文实例讲述了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程序设计有所帮助。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3