jQuery动画animate方法使用介绍

jQuery动画animate方法使用介绍

用于创建自定义动画的函数。 
返回值:jQuery animate(params, [duration], [easing], [callback]) 

如果使用的是“hide”、“show”或“toggle”这样的字符串值,则会为该属性调用默认的动画形式。paramsOptions一组包

含作为动画属性和终值的样式属性和及其值的集合

params 对象{},注意:所有指定的属性必须用骆驼形式,比如用marginLeft代替margin-left,如果使用的是“hide”、

“show”或“toggle”这样的字符串值,则会为该属性调用默认的动画形式。 

duration (可选)三种预定速度之一的字符串("slow", "normal", or "fast")或表示动画时长的毫秒数值(如:1000)

easing (可选)String要使用的擦除效果的名称(需要插件支持).默认jQuery提供"linear" 和 "swing"

callback (可选)Function在动画完成时执行的函数

0.停止动画

1

2

3

if($('.swaplist,.mainlist').is(':animated')){

    $('.swaplist,.mainlist').stop(true,true);

}

 
animate实例:
1.点击按钮后div元素的几个不同属性一同变化

1

2

3

4

5

6

7

8

$("#go").click(function () {

    $("#block").animate({

        width: "90%",

        height: "100%",

        fontSize: "10em",

        borderWidth: 10

    }, 1000);

});

 2.让指定元素左右移动

1

2

3

4

5

6

$("#right").click(function () {

    $(".block").animate({ left: '+50px' }, "slow");

});

$("#left").click(function () {

    $(".block").animate({ left: '-50px' }, "slow");

});

 3.在600毫秒内切换段落的高度和透明度

1

2

3

$("p").animate({

    height: 'toggle', opacity: 'toggle'

}, "slow");

 4.用500毫秒将段落移到left为50的地方并且完全清晰显示出来(透明度为1)

1

2

3

$("p").animate({

    left: 50, opacity: 'show'

}, 500);

 5.切换显示隐藏

1

2

3

4

5

6

7

8

9

10

11

$(".box h3").toggle(function(){

    $(this).next(".text").animate({height: 'toggle', opacity: 'toggle'}, "slow");

        $(this).addClass("arrow");

        return false;

 

    },function(){

        $(this).next(".text").animate({height: 'toggle', opacity: 'toggle'}, "slow");

        $(this).removeClass("arrow");

        return false;

    });

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值