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

change script from window scroll to layer scroll

Status
Not open for further replies.

coolicus

Programmer
May 15, 2007
50
0
0
GB
I found this script on a javascript site that automatically scrolls the window up and down, is it possible to make tchange this to make a layer scroll up and down instead of the whle window??

Code:
<script type="text/javascript">
function page_size() {
  var y, h;
  if(window.innerHeight && window.scrollMaxY)
    y = window.innerHeight + window.scrollMaxY;
  else if(document.body.scrollHeight)
    y = document.body.scrollHeight;
  else y = document.body.offsetHeight;
  if(window.innerHeight) h = window.innerHeight;
  else if(document.documentElement && document.documentElement.clientHeight)
    h = document.documentElement.clientHeight;
  else if(document.body) h = document.body.clientHeight;
  return ((y > h) ? y + 20 - h : false);
}
function init_scroll() {
  init_scroll.height = page_size();
  if(init_scroll.height) {
    init_scroll.y = 0;
    init_scroll.step = 20;
    make_scroll();
  }
}    
function make_scroll() {
  var y = (init_scroll.y += init_scroll.step);
  if(y >= 0 && y <= init_scroll.height) {
    window.scroll(0, y);
    setTimeout(make_scroll, 600);
  }
  else {
    init_scroll.step = -init_scroll.step;
    setTimeout(make_scroll, 2000);
  }
}
onload = init_scroll;
</script>
 
Sure! You might pass in the object and use that instead of the window object.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
sorry for being a muppet here but how do I do that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top