Jump to content

code to scroll the webpage to the middle onload


bindiya

Recommended Posts

I have a javascript code

window.scroll(0,1200);

 

which used to scroll the webpage vertically onload to the middle.But now it is not working!

 

is there any other code available(either in jquery or javascript) that help to scroll the page to the half of the page.

 

thanks

 

this is my javascript code.The code in yellow is for scrolling of images,both need to be called on page load

 

function pageScroll() {

    window.scrollBy(0,1000);

var c=0;

var s;

s=setTimeout("photoGallery();",12000 );

}

 

var c=0;

var s;

function photoGallery()

{

if (c%3==0){

document.getElementById('photo-gallery').src = "images/TIME1.gif";

}

if (c%3==1){

document.getElementById('photo-gallery').src = "images/TIME2.gif";

}

if (c%3==2){

document.getElementById('photo-gallery').src = "images/TIME3.gif";

}

c=c+1;

s=setTimeout("photoGallery();",12000 );

 

}

 

 

  </script>

</head>

<body onLoad="pageScroll();">

"c%3==0" ?

 

Is this some kind of formatting error from posting, or is that actually your code? Most likely that would trigger a syntax error (check the error console, in FF it's under "Tools" > Error Console"), which would prevent the rest of the code from working.

 

Edit: by the way the yellow wasn't a good choice. I had to highlight it to read it - use


tags in future.

nothing that sort ,i checked even by blocking that particular function and running only window.scrollBy(0,2000);

no scrolling takes place.

 

You say "only running window(...)" - did you bind it to the window.onload event? Could you show the code you were testing here?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.