JQ 的animate动画详解

<style>
#div1{ width:200px; height:200px; background:red;}
#div2{ width:200px; height:200px; background:red; margin-top:10px;}
</style>
<body>
<input type="button" value="点击" id="input1">
<div id="div1"></div>
<div id="div2"></div>
</body>
<script>

//animate() : 
//第一个参数 : 对象 {} 去设置样式属性和值(目标点)
//第二个参数 : 时间 默认是400
//第三个参数 : 运动形式 只有两种 swing(默认 : 缓冲 : 慢快慢)  linear(匀速的)
//第四个参数 : 运行结束的回调

$(function(){  
    $('#input1').click(function(){     
        $('#div1').animate({
            width : 400
        },2000,'swing',function(){
            alert(123);
        });
    }); 
});
</script>

每点击一次,移动固定的值(累加)

<script>
$(function(){  
    $('#input1').click(function(){
        $('#div1').animate({
            width : '+=100'
        },1000,'linear');       
    });
});
</script>
<script>
$(function(){  
    $('#input1').click(function(){     
        $('#div1').animate({
            width : 300
        },{
            duration : 1000,
            easing : 'linear',
            complete : function(){
                //alert(123);
            },
            step : function(a,b){  
                //console.log(a);//可以检测我们定时器的每一次变化
                console.log(b.pos);   //运动过程中的比例值(0~1)
            }
        });     
    }); 
});
</script>

step应用,使某个值在两秒钟到达终点

<script>
$(function(){  
    $('#input1').click(function(){     
        $('#div1').animate({
            num : "move"//任意设置,不可不写
        },{
            duration : 2000,
            easing : 'linear',
            complete : function(){
                //alert(123);
            },
            step : function(a,b){  //可以检测我们定时器的每一次变化
                //console.log(a);
                //console.log(b.pos);   //运动过程中的比例值(0~1)
                $('#div1').html(parseInt(b.pos * 273826678));//两秒钟使div1中数字变化到273826678
            }
        });     
    }); 
});
</script>

等待时间delay()

<script>
$(function(){  
    $('#input1').click(function(){     
        $('#div1').animate({width : 300},1000).delay(1000).animate({height : 300},1000);   //当宽变为300后,等待1000毫秒,再运动高    
    }); 
});
</script>

stop()停止运动,清除队列

<script>
$(function(){  
    $('#input1').click(function(){     
        $('#div1').animate({width : 300},1000).animate({height : 300},1000);       
    });

    $('#input2').click(function(){     
        //$('#div1').stop();    //默认情况下 : 只会停止当前运动     
        //$('#div1').stop(true);  //第一个参数 : 可以停止所有的运动      
        //$('#div1').stop(true,true); //第二个参数 : 可以停止到指定的目标点(当前的)       
        $('#div1').finish();//所以运动立即到达终点       
    });

});
</script>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值