繁体   English   中英

我如何使用journalHeight修复jquery noConflict?

[英]How can I fix jquery noConflict, with aboveHeight?

这段jQuery代码运行良好,但是我想实现一个固定点,我想用一个相对点(来自CSS)替换510:#content

var _rys = jQuery.noConflict();
            _rys("document").ready(function () {
                _rys(window).scroll(function () {
                    if (_rys(this).scrollTop() > 510) {
                        _rys('.navigation').addClass("fixed");
                    } else {
                        _rys('.navigation').removeClass("fixed");
                    }
                });
            });

我转换了此代码,但无法正常工作,并且我不明白为什么:)预先感谢您的帮助。

jQuery(document).ready(function() {
var aboveHeight = $('header').outerHeight();
$(window).scroll(function(){
        if ($(window).scrollTop() > aboveHeight){
              $('.navigation').addClass("fixed");
                    }
        else {
              $('.navigation').removeClass("fixed");
                    }
        });
    });

工作版本:感谢Dinesh Kumar DJ

jQuery(window).load(function() {
var aboveHeight = jQuery('#content').offset().top;
            console.log(jQuery('#content'));
jQuery(document).scroll(function(){
    if (jQuery(window).scrollTop() > aboveHeight){
      jQuery('.navigation').addClass("fixed");
    } else {
      jQuery('.navigation').removeClass("fixed");
    }
});   });

将所有$替换为jQuery,它将正常工作,

jQuery(document).ready(function() {
    var aboveHeight = jQuery('header').outerHeight();
    jQuery(window).scroll(function(){
        if (jQuery(window).scrollTop() > aboveHeight){
          jQuery('.navigation').addClass("fixed");
        } else {
          jQuery('.navigation').removeClass("fixed");
        }
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM