jquery实现曲线运动

今天给大家带来网页实现的曲线运动

这个曲线是基于jquery实现的,具体请看:

首先你要给一个点,定义个样式,如

<style>
    .ds {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      background-color: blue;
      position: absolute;
      top: 200px;
      left: 600px;
    }
</style>

然后是对页面盒子的简单布局

  <div class="ds"></div>
  <div class="sdf" onclick="run()">
    点击我执行代码
  </div>

最后是对jQuery等的依赖包的引入和调用

  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
  <script src='./jquery.path.js'></script>
<script type="text/javascript">
    function run() {
      //定义贝塞尔曲线(曲线运动)
      var bezier_params = {
        start: {
          x: 185,
          y: 185,
          angle: -50
        },
        end: {
          x: 540,
          y: 310,
          angle: 50,
          length: 0.85
        }
      }
      //animation时候开始执行
      $(".ds").stop().animate({ path: new $.path.bezier(bezier_params) }, 800, function () { })

      /*圆周运动动画,需要的话可以解开*/
      // var arc_params = {
      //   center: [285, 185],
      //   radius: 200,
      //   start: 0,
      //   end: 1,
      //   dir: -1
      // }

      // $(".ds").animate({ path: new $.path.arc(arc_params) }, 2000, function () { run() });
    }
  </script>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值