【问题标题】:If scroll inside If is visible如果在 If 内部滚动是可见的
【发布时间】:2014-07-14 20:40:41
【问题描述】:

我需要附上这个脚本

var _rys = jQuery.noConflict();
_rys("document").ready(function(){
    _rys(window).on("scroll",function() {
    var height = $(window).height();
        if (_rys(this).scrollTop() > height) {
         _rys('#splash').remove(); 
         window.scrollTo(0, 0); 
          _rys(this).unbind("scroll");    
    } else {
        }
    }); 
});

进入一个如果可见的条件

if( $('#splash').is(':visible') ) {
    // it's visible, do something
}

但我无法让它工作。我只希望在启动层可见时运行滚动脚本,否则每次都会滚动到顶部

提前谢谢你

【问题讨论】:

  • 为什么要重新定义$ 并立即在ready 函数中使用它的新值_rys(仅比jQuery 少2 笔)?然后你打电话给$(window)?

标签: jquery if-statement scroll unbind


【解决方案1】:

只需将其添加到条件中

var _rys = jQuery.noConflict();

_rys(document).ready(function(){

    _rys(window).on("scroll",function() {
        var height = $(window).height();

        if (_rys(this).scrollTop() > height && $('#splash').is(':visible')) {
            _rys('#splash').remove(); 
             window.scrollTo(0, 0); 
             _rys(this).off("scroll");    
        }

    }); 

});

【讨论】:

    猜你喜欢
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多