Click to See Complete Forum and Search --> : need help modifying script!!!


shishkabobs
03-13-2003, 12:58 PM
I got this from dynamic drive, and right now it makes my window scroll repeatedly. I would like to change it so that it only scrolls once... and I would love it if when I actually moved the scroll bar manually, it stopped scrolling as well. Anyone got any ideas???


<script language="JavaScript1.2">

/*
Left-Right scrolling window Script-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more free DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

//change speed to another integer to alter the scrolling speed. Greater is faster
var speed=1
var currentpos=0,alt=1,curpos1=0,curpos2=-1
function initialize(){
startit()
}
function scrollwindow(){
if (document.all)
temp=document.body.scrollLeft
else
temp=window.pageXOffset
if (alt==0)
alt=1
else
alt=0
if (alt==0)
curpos1=temp
else
curpos2=temp
if (curpos1!=curpos2){
if (document.all)
currentpos=document.body.scrollLeft+speed
else
currentpos=window.pageXOffset+speed
window.scroll(currentpos,0)
}
else{
currentpos=0
window.scroll(currentpos,0)
}
}
function startit(){
setInterval("scrollwindow()",10)
}
window.onload=initialize
</script>


- see an example here: http://www.dynamicdrive.com/dynamicindex8/leftscroll.htm

Sergey Smirnov
03-13-2003, 01:17 PM
Enjoy.


<script language="JavaScript1.2">

/*
Left-Right scrolling window Script-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more free DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

//change speed to another integer to alter the scrolling speed. Greater is faster
var intHandler;
var speed=1
var currentpos=0,alt=1,curpos1=0,curpos2=-1
function initialize(){
startit()
}
function scrollwindow(){
if (document.all)
temp=document.body.scrollLeft
else
temp=window.pageXOffset
if (temp!=currentpos) {
clearInterval(intHandler)
return
}
if (alt==0)
alt=1
else
alt=0
if (alt==0)
curpos1=temp
else
curpos2=temp
if (curpos1!=curpos2){
if (document.all)
currentpos=document.body.scrollLeft+speed
else
currentpos=window.pageXOffset+speed
window.scroll(currentpos,0)
}
else{
clearInterval(intHandler)
}
}
function startit(){
intHandler=setInterval("scrollwindow()",10)
}
window.onload=initialize
document.onclick=function(){clearInterval(intHandler)}
</script>

shishkabobs
03-13-2003, 04:47 PM
thanks so much!!!!

got another question now - is there a way that I can get it to stop scrolling if I click on the screen???

Sergey Smirnov
03-13-2003, 04:57 PM
Do you want to stop scrolling when you click on any place of the browser window or only on scrolling image?
Answer depends of it.

shishkabobs
03-13-2003, 05:11 PM
I would like it to stop when you click on any place inside the window that is scrolling.

Jona
03-13-2003, 05:15 PM
I dunno, because I hardly ever use setInterval but wouldn't it be:

window.onclick=clearInterval("scrollwindow()","10");

:confused: Just wondering...

Sergey Smirnov
03-13-2003, 05:41 PM
Actually, it should be:

document.onclick=function(){clearInterval(intHandler)}

shishkabobs, see the changes in the code above

Jona
03-13-2003, 05:46 PM
Oh, yah, that's right.