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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with DHTML doScroll() script

Status
Not open for further replies.

xStrongTowerx

Programmer
Apr 7, 2003
11
US
Dear Forum,

Here's my problem:

I'm trying to write a doScroll script that scrolls a text element (div style="overflow: hidden"), but no matter what I try, the scrolling does not stop on mouseup.

The inline HTML calls it this way:
<img id=&quot;DownArrow&quot; src=&quot;images/scroll-down.gif&quot; height=&quot;4&quot; width=&quot;9&quot; onmousedown=&quot;ScrFunct2('ScrollBarDown');&quot; onmouseup=&quot;ClearIt();&quot;>

This is the script:

Function ScrFunct2(sScrollAction)
BodyText.doScroll(sScrollAction)
window.document.recalc(true)
if BodyText.scrollHeight - BodyText.clientHeight >= BodyText.scrollTop then
DownArrow.setCapture(true)
iTimerID = window.setTimeout(&quot;ScrFunct2('ScrollBarDown')&quot;,200)
End if
End Function

Function ClearIt()
window.ClearTimeout(iTimerID)
window.document.recalc(true)
End Function

What am I missing here?

Thanks,

xSTx
 
Are you declaring your time out variable outside your ScrFunct function.

Example:

var iTimerID;

Function ScrFunct2(sScrollAction)
BodyText.doScroll(sScrollAction)
window.document.recalc(true)
if BodyText.scrollHeight - BodyText.clientHeight >= BodyText.scrollTop then
DownArrow.setCapture(true)
iTimerID = window.setTimeout(&quot;ScrFunct2('ScrollBarDown')&quot;,200)
End if
End Function

If you are not declaring you variable outside the function when you go to clear it it is not accessing the correct variable.
MrGreed

&quot;did you just say Minkey?, yes that's what I said.&quot;
 
Hmmm... That didn't make a difference. I think the variable had been created implicitly.
 
Implicitly? Even worse!

When ScrFunct2( ) exits, iTimerID is discarded.

Explicitly declare it globally, and always use Option Explicit in every <script> bock.
 
I think I fixed it.

<div id=&quot;BodyText&quot; style=&quot;position: relative; top: 0px; left: 0px; height: 145px; width: 204px; font: 7pt Verdana; text-align: justify; color: #FFFFFF; overflow: hidden;&quot; onmousewheel=&quot;ScrFunct()&quot;><div>Text Goes Here.</div></div>
Then...
<script language=&quot;VBScript&quot;>

Dim iTimerID

Function ScrFunct()
If window.event.wheeldelta = -120 then
BodyText.doScroll(&quot;ScrollBarDown&quot;)
Else
BodyText.doScroll(&quot;ScrollBarUp&quot;)
End if
End Function

Function ScrFunct2(sScrollAction)
BodyText.doScroll(sScrollAction)
window.document.recalc(true)
iTimerID = window.setTimeout(&quot;ScrFunct2('&quot; & sScrollAction & &quot;')&quot;,100)
End Function

Function ClearIt()
window.ClearTimeout(iTimerID)
window.document.recalc(true)
End Function

</script>

You can try it out at Thanks for you help. I think Dimming the iTimerID variable made a big difference.

Thanks,

xSTx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top