Welcome to WebmasterWorld Guest from 3.227.3.146

Forum Moderators: open

Message Too Old, No Replies

Scrolling

Scrolling Automatically

     
2:43 am on Nov 1, 2003 (gmt 0)

New User

joined:Oct 20, 2003
posts:6
votes: 0


I need my webpage to scroll automatically when the body loads.ie i need to scroll 200 x axis
i need it happen <body onload="some code">
please help me
Thanx in advance
from
Manickam

[edited by: korkus2000 at 2:59 am (utc) on Nov. 1, 2003]
[edit reason] No sigs please [/edit]

12:54 pm on Nov 1, 2003 (gmt 0)

Senior Member from GB 

joined:Oct 2, 2003
posts:1019
votes: 39


Hi there maxthebg
This is the the code that you need...

<html>
<head>
<style type="text/css">
<!--
div{position:absolute;left:200px;top:800px;}
//-->
</style>
</head>

<body onload="scrollTo(200, 800)">

<div>this div is 200px from the left and 800px from the top </div>
</body>
</html>

birdbrain

4:05 pm on Nov 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2002
posts:710
votes: 0


Is there a way to have it just scroll to the bottom of the page?
5:25 pm on Nov 1, 2003 (gmt 0)

New User

joined:Oct 20, 2003
posts:6
votes: 0


thanx bird for the help.hey guys u can also use this javascript to scroll down or up using a link
250 is the y axis value,x-0.ok
<a class=small href="javascript:window.scrollTo(0,250);">To top ^</a>
thank u
Manickam

[edited by: korkus2000 at 6:15 pm (utc) on Nov. 1, 2003]
[edit reason] No sigs Please [/edit]

1:51 am on Nov 2, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0


I just recently found out that you can also set the scrollTop (and scrollLeft) property of an object, so I was thinking you could also do it like this...

document.body.scrollTop = 250;

...but that only works in Mozilla and IE for the document.body object (Opera7 just sits ther for some reason?), and offsetTop is read-only so that won't work either. The window.scrollTo() method is the only way to go I guess. :)

--------

jamesa:

To get it to scroll all the way to the bottom you can do something like...

if (document.body.scrollHeight) { 
window.scrollTo(0. document.body.scrollHeight);
}
else if (screen.height) { // IE5
window.scrollTo(0. screen.height);
}

Jordan

11:09 am on Nov 2, 2003 (gmt 0)

Senior Member from GB 

joined:Oct 2, 2003
posts:1019
votes: 39


Hi there MonkeeSage,

You have made a slight error in your code...
using a

.
instead of a
,
in these lines

window.scrollTo(0. document.body.scrollHeight);

and

// IE5 window.scrollTo(0. screen.height);


jamesa:

I presume that you require it scroll onload, so the script
would look something like this


<script type="text/javascript">
<!--
function doit()
{
if (document.body.scrollHeight)
{
window.scrollTo(0, document.body.scrollHeight);
}
else if (screen.height)
{
// IE5 window.scrollTo(0, screen.height);
}
}
//-->
</script>

with this in the body tag


onload="doit()"

birdbrain