滚动内嵌框架

发布于 2024-11-19 21:13:04 字数 474 浏览 1 评论 0原文

我有两个窗口:一个是要位于 iframe 中的页面,另一个是要容纳 iframe 的页面。我的项目的目标是制作一个滚动的 iframe,但是当鼠标悬停在其上时,它会暂停。我目前在 iframe 中的页面有以下代码: http://dabbler.org/edit/asdf/scrolling/index.html 以及用于容纳 iframe 的页面代码: http://dabbler.org/edit/asdf/scrolling/index2.html

我的代码有什么问题吗? (是的,我知道我没有 body、head、HTML 和其他内容,这不是问题,因为这些内容是在解释页面时自动插入的)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雄赳赳气昂昂 2024-11-26 21:13:05

window.onmouseover 和 window.onmouseout 未正确定义。

您有这样的情况:

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

您想要这样做:

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

您将 onmouseout 和 onmouseover 设置为调用 pageScroll 和 unpageScroll 的返回值,但您想将 onmouseout/onmouseover 设置为 pageScroll 和 unpageScroll 函数。

最后,您在 setTimeout 中调用了错误的函数。

您正在调用 pageScroll,但您希望调用 pageScroller,它会执行实际的滚动。

编辑

 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;

顺便说一句,当页面尽可能垂直滚动时,您应该在将来的某个时刻处理在 pageScroller 中调用clearTimeout。如果窗口已经尽可能滚动,那么继续调用scrollBy是没有意义的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文