zoukankan      html  css  js  c++  java
  • 逐帧动画的使用

    1、如果对性能要求不高可以直接使用jquery的animate

      $(".nowGift" + heartNumber + "").animate({ right: (x += x_step) + 'px', bottom: (y += a * x_step + 1.5) + 'px', opacity: (300 - y) / 300 }, speed, function () {
        if (y > 300) {
          $(".nowGift" + heartNumber + "").remove();
        }else{
          count++;
          heartMove(x, y, a, x_step, heartNumber, speed, count);//回调函数。
        }
      });
    

     注意:这会导致jQuery的bug,窗口失去焦点时停止触发。

    2、可以使用第二种方案,直接替代jquery的animate使用velocity.js直接替代animate

      $(".nowGift" + heartNumber + "").velocity({ right: (x += x_step) + 'px', bottom: (y += a * x_step + 1.5) + 'px', opacity: (300 - y) / 300 }, speed, function () {
        if (y > 300) {
          $(".nowGift" + heartNumber + "").remove();
        }else{
          count++;
          heartMove(x, y, a, x_step, heartNumber, speed, count);//回调函数。
        }
      });
    

     性能会更好,而且不会引发那个bug

    3、可以直接使用css3的transition或者使用setTimeout

      $(".nowGift" + heartNumber + "").css({'right': (x += x_step) + 'px', 'bottom': (y += a * x_step + 1.5) + 'px', 'opacity': (300 - y) / 300 })
      if (y > 300) {
        $(".nowGift" + heartNumber + "").remove();
      }else{
        setTimeout(function(){
          count++;
          heartMove(x, y, a, x_step, heartNumber, speed, count);//回调函数。
        },20)
      }
    

      效果可能会差一点需要调节,不过性能方面也是可以的  

  • 相关阅读:
    乘法逆元
    P1082 同余方程
    数论编程
    倍增LCA模板
    快速幂模板Super
    黑白染色的模板
    暑假提高组集训Day1 T2
    暑假提高组集训Day1 T1
    7月18日刷题记录 二分答案跳石头游戏Getting
    hdu4738(割桥)
  • 原文地址:https://www.cnblogs.com/huangqiming/p/9517910.html
Copyright © 2011-2022 走看看