jQuery之动画animate(animate、stop、finish、delay、queue、clearQueue)

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></title>
  <style>
    .demo {
      width: 0;
      height: 0;
      position: absolute;
      background-color: #ff0000;
    }

    .demo2 {
      width: 0;
      height: 0;
      position: absolute;
      top: 100px;
      background-color: #0000ff;
    }
  </style>
</head>

<body>
  <div class="demo"></div>

  <div class="demo2"></div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
  //animate动画
  $('.demo').animate({ width: '+=50', height: '+=50', top: '+=100', left: '+=100' }, 1000, 'swing', function () {
    console.log('animate')
  })

  //使动画执行两次或者多次
  $('.demo2')
    .animate({ width: '+=50', height: '+=50', top: '+=100', left: '+=100' }, 1000, 'swing', function () { })
    .animate({ width: '+=50', height: '+=50', top: '+=100', left: '+=100' }, 1000, 'swing', function () { })
</script>

</html>

stop、finish、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></title>
  <style>
    .demo {
      width: 0;
      height: 0;
      position: absolute;
      background-color: #ff0000;
    }
  </style>
</head>

<body>
  <button id="stopBtn">stop</button>
  <button id="finishBtn">finish</button>
  <button id="startBtn">start</button>
  <div class="demo"></div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
  //使动画执行两次或者多次
  //delay(2000):使动画延迟2秒
  $('#startBtn').on('click', function () {
    $('.demo')
      .animate({ width: '+=50', height: '+=50', top: '+=100', left: '+=100' }, 1000, 'swing', function () { })
      .delay(2000)
      .animate({ width: '+=50', height: '+=50', top: '-=200', left: '+=100' }, 1000, 'swing', function () { })
  })

  //使动画停止
  $('#stopBtn').on('click', function () {
    $('.demo').stop()
  })

  //使动画直接完成
  $('#finishBtn').on('click', function () {
    $('.demo').finish()
  })
</script>

</html>

queue 、clearQueue

<!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></title>
  <style>
    .demo {
      width: 0;
      height: 0;
      position: absolute;
      background-color: #ff0000;
    }
  </style>
</head>

<body>
  <div class="demo"></div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
  //queue队列方法
  $('.demo')
    .queue('chain', function (next) {
      console.log('over1')
    })
    .queue('chain', function (next) {
      console.log('over2')
    })
    .queue('chain', function (next) {
      console.log('over3')
    })

  console.log($('.demo').queue('chain'))

  //清除队列
  console.log($('.demo').clearQueue('chain'))
  console.log($('.demo').queue('chain'))
</script>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值