javascript - 滚动窗口在鼠标悬停时滚动

标签 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 --->

最佳答案

这个简单的脚本似乎有效,也许您可​​以从中推断出如何更改您的脚本: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);

关于javascript - 滚动窗口在鼠标悬停时滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6669776/

相关文章:

javascript - Internet Explorer 挂起问题

javascript - 我怎样才能给一个数组作为选择元素的选项?

c# - HangFire 服务器启用 - 手动禁用

javascript - HTML : Photo swipe is not workling

asp.net - 如果用户 = XXX 访问者,提示输入电子邮件...?

javascript - 我如何使用 JavaScript (jQuery) 按照惯例在 HTML 中创建一个元素的副本作为新元素?

asp.net - 如何获取 web.config 中的 configSections 列表

asp.net - 从 Web 应用程序向 Windows 应用程序发送击键

html - 在 Angular Material 中隐藏来自 mat-form-field 的箭头

html - 如何将边框半径设置为表格边框?