开发者

jQuery Animate div position

I want to animate a div by changing it's top property like so:

var loadingFrame = 1; loadingFrame = (loadingFrame + 1) % 12;开发者_运维百科

// Loading animation
jQuery('div.ModalLoading div').animate('top', (loadingFrame * -40) + 'px');

The idea is that the inner div will look like it is sliding up inside the ModalLoading div, and needs to continue infinite. At the moment the div is stationary. Thanks.

EDIT: This based upon the loading in FancyBox --> http://fancybox.net/ if that helps anyone debug my code.

div.ModalLoading
{
    height: 40px; width: 40px; margin: 0 auto 20px; overflow: hidden; z-index: 1104; position: relative;
}
div.ModalLoading div
{
    position: absolute; top: 0; left: 0; width: 40px; height: 480px; background: url('loading.png');
}


Hmm, ive just tried and the best i can do is this.

var loadingFrame = 1; loadingFrame = (loadingFrame + 1) % 12;

function startLoader(loopint,_left,_right)
{
    settings = {};
    if(_left && !_right)
    {
        settings.left = (((loadingFrame + 1) % 12) * -40)
        var _callback = function(){startLoader(loopint,false,true)}
    }else{
        settings.left = (((loadingFrame + 1) % 12) * +40)
        var _callback = function(){startLoader(loopint,true,false)}
    }

    jQuery('.inner').animate(settings,loopint,_callback);
}

and start the animation.

startLoader(5000);

Example here: http://jsfiddle.net/v8rvM/2/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜