简体   繁体   中英

Scrolling Iframe

I have two windows: One is a page meant to be in an iframe, and one is the page meant to house the iframe. The objective of my project is to make an iframe that scrolls, but, when it is moused over, it pauses. I currently have the following code for the page meant to be in an iframe: http://dabbler.org/edit/asdf/scrolling/index.html and the code for the page meant to house the iframe: http://dabbler.org/edit/asdf/scrolling/index2.html

What is wrong with my code? (Yes, I know I don't have body, head, HTML and the others, that isn't the problem, for those are thrust in automatically when the page is interpreted)

The window.onmouseover and window.onmouseout are not defined correctly.

You have this:

 window.onmouseout = pageScroll();     
 window.onmouseover = unpageScroll();

You want to do this:

 window.onmouseout = pageScroll;     
 window.onmouseover = unpageScroll;

You were setting onmouseout, and onmouseover to the return values of calling pageScroll and unpageScroll, but you wanted to set onmouseout/onmouseover the functions pageScroll and unpageScroll.

And finally, you're calling the wrong function in your setTimeout .

You are calling pageScroll, but you want to be calling pageScroller , which does the actual scrolling.

EDIT

 function pageScroll(){
            num = 150;
            clearTimeout(scrolldelay);
            pageScroller();
 }
  function unpageScroll(){num = 15000000;}
  function pageScroller() {
    window.scrollBy(0,50); // horizontal and vertical scroll increments
    scrolldelay = setTimeout('pageScroller()',num); // scrolls every 100 millisecond
  }
  var num = 50;
  window.onmouseout = pageScroll;
  window.onmouseover = unpageScroll;

BTW, you should handle calling clearTimeout in pageScroller at some point in the future when the page is scrolled vertically as much as possible. There's no point in continuing to call scrollBy if the window is already scrolled as much as possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM