Force jQuery animations to use integer values

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 10:22:26

For me this worked in the right way:

$("div").animate({ width: 50}, {
    duration: 1000,
    step: function(now, fx){
        fx.now = parseInt(now);
    }
});​

Something like this?

$("div").animate({ width: 50}, {
  duration: 1000,
  step: function(now, fx){

      var value = parseInt($(this).css("width"));

     $(this).css("width", value);
  }
});​

This way, in each "frame" of the animation, the width value will be parsed into an integer value.

The animation will be less smoother this way, since you're cutting some values, but if your animation is long enough, it won't be even noticed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!