Continuous animation on hover (performance)

前端 未结 2 1438
攒了一身酷
攒了一身酷 2021-02-06 07:11

I\'ve created a jQuery function that scrolls a DIV by decreasing the left-margin of the element. It works, but it\'s incredibly slow. It eats up 100% CPU in no time :s



        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 07:43

    .animate() is a good way to do it. Example:

    $(".scroll").hover(function(){
      $("#content").animate({
        marginLeft: "100px",
      }, 1500 );
    });​
    

    Working DEMO

    Read the documentation to get the idea how to use it.

提交回复
热议问题