2011-07-12 112 views
0

本质上,它应该是一个滚动的iFrame,一旦它触及底部,重置到顶部。这些功能都可以正常工作。但是,(注意这是在一个.asp文件中)我还需要一个函数,当用户将鼠标悬停在窗口上时,停止滚动。它可以工作,但是当用户将鼠标放在窗口周围时,不要让鼠标保持静止,滚动就会发生,事实上,它甚至会更快地滚动。有什么建议么?滚动鼠标滚动窗口滚动

<html> 
    <head> 
     <link href="intranet.css" rel="stylesheet" type="text/css"> 
     <style> 
     </style> 
     <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js" type="text/javascript"></script> 
     <script type="text/javascript"> 
      var num2 = 3; 
      function getheight() { 
       console.log(num2); 
       var myWidth = 0, 
      myHeight = 0; 
       if (typeof (window.innerWidth) == 'number') { 
        //Non-IE 
        myWidth = window.innerWidth; 
        myHeight = window.innerHeight; 
       } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { 
        //IE 6+ in 'standards compliant mode' 
        myWidth = document.documentElement.clientWidth; 
        myHeight = document.documentElement.clientHeight; 
       } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { 
        //IE 4 compatible 
        myWidth = document.body.clientWidth; 
        myHeight = document.body.clientHeight; 
       } 
       var scrolledtonum = window.pageYOffset + myHeight + 2; 
       var heightofbody = document.body.offsetHeight; 
       if (scrolledtonum >= heightofbody) { 
        window.scroll(0, 0); 
       } 
      } 

      window.onscroll = getheight; 

      function pageScroll() { 
       num2 = 3; 
       clearTimeout(scrolldelay); 
       pageScroller(); 
      } 
      function unpageScroll() { num2 = 0; } 
      function pageScroller() { 
       window.scrollBy(0, num2); 
       scrolldelay = setTimeout('pageScroller()', num); 
      } 
      var num = 50; 
      window.onmouseout = pageScroll; 
      window.onmouseover = unpageScroll; 
     </script> 
    </head> 
    <body onLoad="pageScroller()"> 
    <p></p> 
    <br /> 
    <p></p> 
    <br /> 
    <div id="datacontainer" style="position:relative;width:100%;text-align:center;" onMouseover="unpageScroll" onMouseout="unpageScroll"> 

    <!-- ADD YOUR SCROLLER COMMENT INSIDE HERE---------------------> 
    <font face="Arial, Helvetica, sans-serif" size="1"> 
    <br> 
    <center> 
    <font size=2> 
<!-- CONTENT--> 
<!-- Closing tags ---> 

回答

0

这个简单的脚本似乎工作,也许你可以从中推断如何改变你的脚本:http://jsfiddle.net/xkuZF/1/

function func() { 
    document.body.scrollTop++; 
} 

document.body.onmouseover = function() { 
    clearInterval(interval); 
}; 

document.body.onmouseout = function() { 
    interval = setInterval(func); 
}; 

var interval = setInterval(func); 
+0

我运行它时出现错误:未捕获的类型错误:无法设置null属性的'onmouseout' - 任何想法? – Guy

+0

@Guy:这意味着'document.body'是'null'(非常不可能 - 在你的场景中可能吗?)。如果你使用'document.onmouseout'呢? – pimvdb

+0

是的,我相信是的。什么会表明这一点?请注意,我在iFrame中使用脚本,这会对我应该使用的代码产生影响吗?另请注意,该页面是asp。 – Guy