Saturday, 15 June 2013

javascript - Function is not working as standalone with $(document).ready -



javascript - Function is not working as standalone with $(document).ready -

i'm trying page autoscroll using jquery animate. simple- loads xml info single div, sets body size size+some amount of pixels. want autoscroll bottom. if utilize code:

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

it working. since utilize function more once, tried this:

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

and i'm done. won't work. tried putting in different parts of website (head, body, changing order of $document.ready , function itself) won't help. tried run function adding onload body element. why can't utilize thing vork.

there error notation of animate function. have write so:

$(document).ready(pagescroll); function pagescroll(){ var z=document.getelementbyid('main_container').clientheight + 2400, speed = z * 3; // 1 way write animate(): $('body,html').animate({scrolltop: z}, speed, "linear"); // way write animate(), take 1 of $('body,html').animate( {scrolltop: z}, { easing: "linear", duration: speed} ); };

see here how utilize animate correctly.

javascript jquery html

No comments:

Post a Comment