一、animate()语法

$(“选择器”).animate({CSS样式},时间,运动方式,回调函数);

参数说明:

参数1:CSS属性名,属性值,JSON格式{"属性名":"属性值"}

参数2:动画执行时间,毫秒

参数3:动画的运动方式,参数要用引号,例如:linear是匀速播放

参数4:回调函数function(){},动画完毕后,执行的函数

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
div{
width:200px;
height:200px;
background: greenyellow;
position:absolute;
top:0;
left:0;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
<script src="js/jquery-1.12.4.min.js"></script>
<script>
$('div').animate({'top':500,'left':400},3000,function(){
$(this).css('backgroundColor','pink');
})
</script>

二、不能参加运动的属性

我们关心的不能参加运动的有哪些?

1、background-color 背景色。但是CSS3可以实现

2、background-position背景定位,但是CSS3可以实现

3、一切的CSS3属性不能动画,border-radius除外。

三、动画排序

一个元素animate的时候,会按顺序执行

//$('div').animate({"left":500},1000);

//$('div').animate({"top":500},1000);

//$('div').animate({"left":0},1000);

//$('div').animate({"top":0},1000);

同一个元素多次打点animate的时候,动画会自动排成队列,谁先写的,谁先执行。

$('div').animate({"left":500},1000).animate({"top":500},1000).animate({"left":0},1000).animate({"top":0},1000);

四、异步语句和回调函数

animate动画方法是一个异步语句,也可以写回调函数,描述运动结束后可以做什么事情。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
div{
width:100px;
height:100px;
background: red;
position:absolute;
top:100px;
left:0;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
<script src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$('div').animate({'left':500},1000,function(){
$(this).css('backgroundColor','blue');
}) </script>

其他方法也都有回调函数:

slideUp()、slideDown()、fadeIn()、fadeOut()、show()、hide()

五、延迟动画delay()

所有动画方法都可以用delay()。表示这动画不是立即执行,要等待一段时间再执行。

参数:规定延迟时间。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
div{
width:100px;
height:100px;
background: red;
position:absolute;
top:0;
left:0; }
</style>
</head>
<body>
<div></div>
</body>
</html>
<script src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
// $('div').delay(1000).slideUp();
// $('div').delay(1000).slideDown();
// $('div').delay(2000).nimate({'left':500},1000) $('div').delay(1000).slideUp().delay(1000).slideDown().delay(2000).animate({'left':500},1000)
</script>

六、stop()停止动画方法

//stop(是否清空动画队列,是否完成当前动画); 默认stop(false,false);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
div{
width:100px;
height:100px;
background: red;
position:absolute;
top:100px;
left:0;
} </style>
</head>
<body>
<input type="button" value="stop()默认flase\false">
<input type="button" value="stop(true)">
<input type="button" value="stop(true,true)">
<input type="button" value="stop(false,true)">
<input type="button" value="finish()">
<div></div>
</body>
</html>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$('div').animate({'left':1000},1500);
$('div').animate({'top':300},1500);
$('div').animate({'left':0},1500);
$('div').animate({'top':100},1500);
//stop(是否清空动画队列,是否完成当前动画);
$('input').eq(0).click(function(){
$('div').stop();// false false
})
$('input').eq(1).click(function(){
$('div').stop(true); //true flase
})
$('input').eq(2).click(function(){
$('div').stop(true,true);
})
$('input').eq(3).click(function(){
$('div').stop(false,true);
})
</script>

七、is(':animated')

is表示“是不是”,而不是“是”,表示检测某一个元素是否具备某种状态,返回true、false的布尔值。

is里面可以写选择器:

1 $(this).is(".t"); //判断当前被点击的p是否有.t这个类名,是就返回true

2 $(this).is("#t"); //判断当前被点击的p是否有#t这个id名,是就返回true

3 $(this).is("p:odd"); //判断当前被点击的p是否是奇数,是就返回true

4 $(this).is("p:lt(3)"); //判断当前被点击的p下标是否小于3,是就返回true

$(this).is("p:visible"); //判断当前被点击的p是否可见

八、动画节流

当一个元素身上被积累了很多动画,不经之间就积累了,我们称为“流氓”

希望新的动画触发时,前面这个动画全部清空,立即停止,防止用户频繁触发事件

方法1:用stop()。清空前面所有动画队列,立即停止当前动画,参数值传第一个true

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
div{
width:100px;
height:100px;
background: orange;
position:absolute;
top:100px;
left:0;
}
</style>
</head>
<body>
<input type="button" value="到0广州">
<input type="button" value="到1000北京">
<div></div>
</body>
</html>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$('input').eq(0).click(function(){
$('div').stop(true).animate({'left':0},1000);
})
$('input').eq(1).click(function(){
$('div').stop(true).animate({'left':1000},1000)
}) </script>

方法2:节流方法,判断元素is()是否在运动过程中,如果是,就不执行后面的操作;如果不是,就执行后面的动画。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style type="text/css">
div{
width:100px;
height:100px;
background: orange;
position:absolute;
top:100px;
left:0;
}
</style>
</head>
<body>
<input type="button" value="到0广州">
<input type="button" value="到1000北京">
<div></div>
</body>
</html>
<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$('input').eq(0).click(function(){
if(!$('div').is(':animated')){
$('div').animate({'left':0}, 2000)
}
})
$('input').eq(1).click(function(){
if(!$('div').is(':animated')){
$('div').animate({"left":1000},2000);
}
}) </script>

jquery-animate()动画的更多相关文章

  1. jquery animate 动画效果使用解析

    animate的意思是:使有生气:驱动:使栩栩如生地动作:赋予…以生命作为形容词:有生命的:活的:有生气的:生气勃勃的 先看动画效果:http://keleyi.com/keleyi/phtml/jq ...

  2. jQuery animate()动画效果

    1.jQuery动画效果 jQuery animate()方法用于创建自定义动画 $(selector).animate({params},speed,callback); //必需的 params ...

  3. jquery animate 动画效果使用说明

    animate( params, [duration], [easing], [callback] ) 用于创建自定义动画的函数. 这个函数的关键在于指定动画形式及结果样式属性对象.这个对象中每个属性 ...

  4. jQuery animate动画 stop()方法详解~

    一.动画格式: 格式一:jQueryObject.animate( cssProperties, options ) 格式二:$('#id').animate( styles[, duration ] ...

  5. jquery animate动画持续运动

    function fingers(){ $(".box01 .fingers").animate({"width":"7.5rem",&qu ...

  6. jquery的动画函数animate()讲解一

    jquery animate 动画效果使用说明 animate( params, [duration], [easing], [callback] ) 用于创建自定义动画的函数. 这个函数的关键在于指 ...

  7. jQuery之动画效果show()......animate()

    jQuery之动画效果 1.show()显示效果 语法:show(speed,callback) Number/String,Function speend为动画执行时间,单位为毫秒.也可以为slow ...

  8. jQuery中animate动画第二次点击事件没反应

    jQuery中animate动画第二次点击事件没反应 用animate做点击翻页动画时发现第二次点击事件动画没反应,而第一次点击有动画效果,代码如下: 复制代码 代码如下: $(".page ...

  9. jquery IE6 下animate 动画的opacity无效

    jquery IE6 下animate 动画的opacity无效,其实是有效的,因为IETester的一个小BUG 原生IE6 没问题...呵呵~~

  10. jQuery 效果 - 动画 animate() 方法

    我们先看一个demo <!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11. ...

随机推荐

  1. 自定义ASP.NET Core日志中间件

    这个日志框架使用的是ASP.NET Core的NLog,用来记录每次请求信息和返回信息. 1.首先创建一个Web应用项目,我选择的是MVC模板: 2.使用NuGet添加Microsoft.Extens ...

  2. selenium和appium启动的感悟

    阅读源码后整理记录如下: selenium : 1.若为webdriver.Chrome()方式启动:①子程序打开chromedriver.exe程序,程序打开后,监听9515端口作为remote_s ...

  3. Q64 最小路径和

    给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小. 说明:每次只能向下或者向右移动一步. 示例: 输入: [ [1,3,1], [1,5,1], ...

  4. 连接Git@OSC操作步骤

    一.准备工作 软件下载 Git:地址 TortoiseGit:地址 二.安装与配置 1.Git安装 Git配置 设置客户端的用户名和email 然后,到Git@OSC 上面注册一个帐号. 这个帐号就是 ...

  5. 移动端优化 && 清除移动端网站点击a标签时闪现的边框或遮罩层(CSS) && 移动端点击 && 文字不可选择

      在移动端网站,当你点击加了a标签的文字或图片时,该元素的周围会闪现一个蓝色的边框,在微信上的网站就是如此:而有的浏览器会闪现一个半透明遮罩层,比如移动端的Chrome浏览器,其实这些特效无非就是为 ...

  6. Nginx PHP fpm forbidden 原因

    可能是标红目录层级不一致 location / { root /var/www/html/public; index index.php; } location ~ \.php$ { root /va ...

  7. 在Ubuntu16.04集群上手工部署Kubernetes

    目前Kubernetes为Ubuntu提供的kube-up脚本,不支持15.10以及16.04这两个使用systemd作为init系统的版本. 这里详细介绍一下如何以非Docker方式在Ubuntu1 ...

  8. JavaScript数据结构-12.散列碰撞(线性探测法)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. (转载)GRASP职责分配原则

    GRASP (职责分配原则) 要学习设计模式,有些基础知识是我们必须要先知道的,设计模式是关于类和对象的一种高效.灵活的使用方式,也就是说,必须先有类和对象,才能有设计模式的用武之地,否则一切都是空谈 ...

  10. python 爬虫入门案例----爬取某站上海租房图片

    前言 对于一个net开发这爬虫真真的以前没有写过.这段时间开始学习python爬虫,今天周末无聊写了一段代码爬取上海租房图片,其实很简短就是利用爬虫的第三方库Requests与BeautifulSou ...