开发者

Scrolling Window Scrolls on Mouseover

Essentially, it is supposed to be a scrolling iFrame, that, once it hits the bottom, resets to the top. These functions all work fine. However, (note that this is in an .asp file) I also need a function that, when the user mouses over the window, stops the scrolling. It works, but when the user mouses around on the window, not keeping their mouse still, the scrolling occurs, in fact, it even scrolls faster. Any suggestions?

    <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 pag开发者_如何学GoeScroller() {
                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 --->


This simple script seems to work, perhaps you can deduce from it how to alter your script: 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜