Wednesday, 15 August 2012

jquery - Creating infinite loop with animate for topscroll -



jquery - Creating infinite loop with animate for topscroll -

i'm trying loop function/animation. want page scroll bottom, jump top , infinitly. have code 1 time:

$(document).ready(pagescroll); function pagescroll() { var z = document.getelementbyid('main_container').clientheight + 2400; var speed = z * 2; window.scroll(0,0); $('body, html').animate({ scrolltop: z }, { easing: "linear", duration: speed }); }

main_container div stretching across page. tried adding pagescroll(); after animate, removing window.scroll(0,0), , adding both pagescroll , pagescroll() after duration:speed, putting in settimeout, nil worked. each illustration found didn't work. how can add together infinite loop function?

you need add together callback animate function, this:

$('body,html').animate( {scrolltop: z}, {easing: "linear", duration: speed}, function() { $('body,html').scrolltop( 0 ); // scroll top when animation finished pagescroll(); // phone call scroll function 1 time again } );

in case function work in recursive way.

jquery

No comments:

Post a Comment