开发者

Cycle animation

开发者 https://www.devze.com 2023-01-20 10:02 出处:网络
<div class=\"wrapper\"> <div class=\"img\">image on background</div> </div> .wrapper { position: relative; }
<div class="wrapper">
    <div class="img">image on background</div>
</div>

.wrapper { position: relative; }
.img { position: absolute; left: 0; top: 0; back开发者_如何学Pythonground: url(image.png); }

.img block must be cycle animated, it should travel from left point of .wrapper to right and then back.

There should be 2 seconds pause, before it will travel back.

How can I do this?


If you just want an image moving right and left across the screen, you can use animate like this:

$(function(){
    var $image = $('div.img'),
        $wrapper = $image.parent(),
        delay = 1000,
        duration = 4000,
        moveRight = function(){
            $image.delay(delay).animate({
                left: $wrapper.width() - $image.width()
            }, {
                duration: duration,
                complete: moveLeft
            });
        },
        moveLeft = function(){
            $image.delay(delay).animate({
                left: 0
            }, {
                duration: duration,
                complete: moveRight
            });
        };

    moveRight();
}); 
0

精彩评论

暂无评论...
验证码 换一张
取 消