Home > Web Front-end > HTML Tutorial > ie8onScroll事件多次激活问题_html/css_WEB-ITnose

ie8onScroll事件多次激活问题_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:42:51
Original
1103 people have browsed it

<script>var s=0;$(document).ready(function(){    $(window).scroll(function(){        var t=$(window).scrollTop();        setTimeout(function(){            if(t!=2000){                $("#msg").html(++s);                $(window).scrollTop(2000);            }        },1000);    });});</script><div style="height:5000px"></div><div id="msg" style="position:fixed;width:100px"></div>
Copy after login

这段代码在IE9 IE10 chrome 显示的结果都是1

在ie8以下,包括ie8 用鼠标滚轮滚动结果是4,点滚动条上的按键 结果是10,

喵了咪的,搞的在ie8 onScroll事件被触发多次,动画效果乱套了。
有没有高手帮忙ie8下如何只触发一次?


回复讨论(解决方案)

$(window).bind("scroll",function(){
//……
}); 试试

ie8-有这个问题。。用计时器来做。

var s=0;$(document).ready(function () {    var timer;    $(window).scroll(function () {        if (timer) clearTimeout(timer)////        timer = setTimeout(function () {/////            var t = $(window).scrollTop();            setTimeout(function () {                if (t != 2000) {                    $("#msg").html(++s);                    $(window).scrollTop(2000);                }            }, 1000);        }, 10);    });});
Copy after login

谢谢两位,回去我试试,手机没测试的

$(window).bind("scroll",function(){  
    //……  
}); 试试
这个不行

ie8-有这个问题。。用计时器来做。

JavaScript code?12345678910111213141516var s=0;$(document).ready(function () {    var timer;    $(window).scroll(function () {        if (timer) clearTimeout(timer)/……
只能用计时器这个了

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template