簡體   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