为了账号安全,请及时绑定邮箱和手机立即绑定

想让某个函数执行一次

想让某个函数执行一次

艳妮子Yeah 2016-11-01 15:08:21
var Height=document.body.clientHeight;$(document).bind("mousewheel DOMMouseScroll scroll", function (e) {        if ($(window).scrollTop()==Height) {            alert(1);        } });为什么alert(1)不执行,改成if ($(window).scrollTop()>=Height) {            alert(1); }时才执行。可是我只想让alert(1)执行一次
查看完整描述

3 回答

已采纳
?
stone310

TA贡献361条经验 获得超191个赞

滚屏速度太快了,可以设定个区域,加个判断条件 或者自己看还有没有更好的办法,匆忙间暂时就这个

var flag=true;
var Height=document.documentElement.clientHeight||document.body.clientHeight;
$(document).bind("mousewheel DOMMouseScroll scroll", function (e) {
    console.log($(window).scrollTop())
    console.log(Height)
    if ($(window).scrollTop()>Height-50 && $(window).scrollTop()<Height+50 && flag==true) {
        alert(1);
         flag=false;
    }
});


查看完整回答
1 反对 回复 2016-11-01
?
李晓健

TA贡献1036条经验 获得超461个赞

Height 哪来的?

查看完整回答
反对 回复 2016-11-01
  • 艳妮子Yeah
    艳妮子Yeah
    var Height=document.body.clientHeight;
  • 李晓健
    李晓健
    因为浏览器滚动时,并不一定是一个像素一个像素的滚动的,所以用等于就可能不会成立。
  • 3 回答
  • 0 关注
  • 1295 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信