continuous movement animation with jquery

前端 未结 4 1898
南旧
南旧 2020-12-24 11:38

continuous movement

I would like to recreate the truck moments in the above site , It is done in mootools. How would I code this, is there a jQuery plugin to do this

4条回答
  •  一向
    一向 (楼主)
    2020-12-24 11:40

    Here's an example of the following code.

    This is relatively simple with jQuery using the position:absolute CSS property and the .animation()[DOCS] method callback. You will basically be animating the left CSS property over a period of time within a named function, then call that function in the animation callback when the animation is complete, like so:

    var animateTruck = function () {
    
        $('#truck').css('left','-50px')
                   .animate({'left':$(window).width()},
                            4000,
                            'linear',
                            function(){
                                animateTruck();
                            });
    };
    
    animateTruck();
    

提交回复
热议问题