31-动画效果

一、显示隐藏

$("div").show();

$("div").hide();

参数为速度,毫秒单位,参数可以为:slow,normal,fast.默认400毫秒。

回调函数

$(document).ready(function(){
   $('div').hide('slow',function(){
    alert('显示完毕!');
   });
});
  1. 列队动画

   $('input:eq(0)').click(function(){
     $('p:eq(0)').hide('slow',function aa(){
          $(this).next('p').hide('slow',aa);
      });
   });

  $('input:eq(1)').click(function(){
     $('p:eq(2)').show('slow',function aa(){
          $(this).prev('p').show('slow',aa);
      });
   });
   
   //显示隐藏开关
    $('input:eq(1)').click(function(){
          $('p').toggle('slow');
   });

2.向上卷动,向下展开

slideUp,slideDown,toggle切换

3.淡入,淡出,参数0-1之间

fadeIn(),fadeOut(),fadeToggle(),fadeTo(0~100);

4.自定义动画

$(document).ready(function(){
  $("input").click(function(){
       $('div').animate({
            width:'200px',
            height:'200px',
            opacity:0.5,
            fontSize:'50px'
       },2000,function(){
             alert('动画执行完毕!');
      });
   });
});

blob.png

5.stop停止动画

$(document).ready(function(){
  $("input[value='开始']").click(function(){
       $('div').animate({ marginLeft:'250px'},3000).delay(5000)
               .animate({ height:'100px' },3000)
               .animate({ width:'200px' },3000);
   });
  $("input[value='停止'").click(function(){
    //停止第一个列队动画,后面继续执行
   // $('div').stop();
   //停止并清除后面的动画
    //$('div').stop(true);
    //停止后停到末尾的位置
    $('div').stop(true,true);
});
});

<body >
 <div style='background:red;position:absolutely;width:100px;'>
  aaaa
</div>
<input type="button" value="开始"/>
<input type="button" value="停止"/>
</body>

6.连续动画

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
  $("input[value='开始']").click(function(){
   
        $('div').slideToggle(2000,function(){
          $(this).slideToggle(2000,arguments.callee);
       });
   });
  $("input[value='停止'").click(function(){
   $(':animated').stop(true);
});
});
</script>
<style>
div{
 position:absolutely;
}
</style>
</head>
<body >
 <div style='background:red;position:absolutely;width:100px;height:300px;'>
  aaaa
</div>
<input type="button" value="开始"/>
<input type="button" value="停止"/>
</body>
</html>

7.$.fx.interval=200;设置动画帧,默认13

  $.fx.off=true;关闭所有动画

8.swing缓动,linear,匀速,运动方式,默认为swing.加在时间参数后面。

<script>
$(document).ready(function(){
  $("input[value='开始']").click(function(){
   
        $('div').slideToggle(2000,'linear',function(){
          $(this).slideToggle(2000,'linear',arguments.callee);
       });
   });
  $("input[value='停止'").click(function(){
   $(':animated').stop(true);
});
});
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

会编程的阿强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值