在鼠标悬停上滚动窗口滚动

时间:2011-07-12 19:16:29

标签: javascript asp.net html css dhtml

基本上,它应该是一个滚动的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 --->

1 个答案:

答案 0 :(得分: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);