Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scrolling a Window Up and Down

Status
Not open for further replies.

megalene

Programmer
Jan 4, 2001
31
Hello All,

I am having a little problem getting my scrolling window to scroll back up. I am enclosing the current code I have, any help would be great.

<script>
<!--
function startAd() {
if (window.screen) {
pos = 0;
aw = parseInt(screen.height);
window.scrollBy(0,pos);
timerID = setInterval(&quot;moveAd()&quot;, 100);
}
}
function moveAd() {
if (pos <= 0) inc = 5;
// 5 - so it doesn't pass the right edge
// 10 - accounts for the window chrome
if (pos + 750 >= aw) inc = -5;
pos += inc;

window.scrollBy(0,pos);
}

//-->
</script>
<body onload=&quot;startAd()&quot;>

The ultimate goal is to get a window to scroll down and then back up.
 
I'll take a look at, but you may want to eventually clearInterval(), otherwise it will keep trying to do this (or is that the effect you want?) jared@aauser.com
 
Thanks for your help, and to respond to your question, yes this should be constant, I will be adding hyper links that will clearInterval or stop it when the user mouses over.
 
what browsers and versions does it have to work in jared@aauser.com
 
Well if I can just get it to work in IE 4 and above that would be cool, I can then figure out a fix to make it cross browser.
 
HEAVILY altered from a dynamicdrive script I found (tested in IE5.5):

//change speed to another integer to alter the scroll speed. Greater is faster
var speed=5
var alt=1,curpos1=0,curpos2=-1

function scrollwindow()
{
temp=document.body.scrollTop;
alt=(alt==0)?1:0;
if(alt==0){curpos1=temp}else{curpos2=temp}
if (curpos1!=curpos2)
{
currentpos=document.body.scrollTop+speed
window.scroll(0,currentpos)
}
else{sendItUp()}
}

function startIt()
{
jack = setInterval(&quot;scrollwindow()&quot;,10)
}

function scrollwindowUp()
{
temp=document.body.scrollTop;
alt=(alt==0)?1:0;
if(alt==0){curpos1=temp}else{curpos2=temp}
if (curpos1!=curpos2)
{
currentpos=document.body.scrollTop-speed
window.scroll(0,currentpos)
}
else{sendItDown()}
}

function sendItUp(x)
{
curpos1=curpos2-1
clearInterval(jack)
jack = setInterval(&quot;scrollwindowUp()&quot;,10)
}

function sendItDown(x)
{
curpos1=curpos2-1
clearInterval(jack)
jack = setInterval(&quot;scrollwindow()&quot;,10)
}

window.onload=startIt

jared@aauser.com
 
Works great, I dont know why I didnt even check dynamic drive for this. Thanks alot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top