最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery no conflict not working - Stack Overflow

programmeradmin1浏览0评论

This is sort of a two question into one. I'm trying to use the jquery no conflict but I don't think I'm doing it correctly.

This is wat I have:

// **************** PLUGINS ****************

jQuery.noConflict() // return `$` to it's previous "owner"
(function($){ // in here you're assured that `$ == jQuery`

$(document).ready(function() {
    $(".fancybox").fancybox(); /*LIGHTBOX*/
});

$(window).scroll(function(){ /*SCROLL TO TOP*/
    if ($(this).scrollTop() > 100) {
        $('.scrollup').fadeIn();
    } else {
        $('.scrollup').fadeOut();
    }
}); 

$('.scrollup').click(function(){
    $("html, body").animate({ scrollTop: 0 }, 600);
    return false;
});

$('.bxslider').bxSlider();

});

Am i not doing it right?

*

Also, when I add this it makes everything stop working which is why I think I'n not adding the no conflict correctly:

*

// **************** HEADER SHADOW ****************

$(window).scroll(function() {
    if ($(this).scrollTop() == 0) {
        $('header').css({
                'box-shadow': 'none',
                '-moz-box-shadow' : 'none',
                '-webkit-box-shadow' : 'none' });
    }
    else {
        $('header').css({
                'box-shadow': '0px 10px 10px #888',
                '-moz-box-shadow' : '0px 10px 10px #888',
                '-webkit-box-shadow' : '0px 10px 10px #888' });
    }
});

Thank you in advance.

This is sort of a two question into one. I'm trying to use the jquery no conflict but I don't think I'm doing it correctly.

This is wat I have:

// **************** PLUGINS ****************

jQuery.noConflict() // return `$` to it's previous "owner"
(function($){ // in here you're assured that `$ == jQuery`

$(document).ready(function() {
    $(".fancybox").fancybox(); /*LIGHTBOX*/
});

$(window).scroll(function(){ /*SCROLL TO TOP*/
    if ($(this).scrollTop() > 100) {
        $('.scrollup').fadeIn();
    } else {
        $('.scrollup').fadeOut();
    }
}); 

$('.scrollup').click(function(){
    $("html, body").animate({ scrollTop: 0 }, 600);
    return false;
});

$('.bxslider').bxSlider();

});

Am i not doing it right?

*

Also, when I add this it makes everything stop working which is why I think I'n not adding the no conflict correctly:

*

// **************** HEADER SHADOW ****************

$(window).scroll(function() {
    if ($(this).scrollTop() == 0) {
        $('header').css({
                'box-shadow': 'none',
                '-moz-box-shadow' : 'none',
                '-webkit-box-shadow' : 'none' });
    }
    else {
        $('header').css({
                'box-shadow': '0px 10px 10px #888',
                '-moz-box-shadow' : '0px 10px 10px #888',
                '-webkit-box-shadow' : '0px 10px 10px #888' });
    }
});

Thank you in advance.

Share Improve this question asked Feb 18, 2013 at 16:16 DanielDaniel 552 silver badges10 bronze badges 2
  • When you say "add this", you mean inside the block (function($){ })(jQuery) or after ? EDIT : following Robert's answer I see you just forgot to pass jQuery... – Denys Séguret Commented Feb 18, 2013 at 16:18
  • In the same block, so it's all one thing. For the purpose of this question it's shwoing separate but I was just copying and pasting under the $('.bxslider').bxSlider(); – Daniel Commented Feb 18, 2013 at 16:38
Add a ment  | 

1 Answer 1

Reset to default 8

You have to pass jQuery in to you function:

jQuery.noConflict() // return `$` to it's previous "owner"
(function($){ // in here you're assured that `$ == jQuery`

    // Code

})(jQuery); //Do you mean to pass jQuery like this perhaps?
发布评论

评论列表(0)

  1. 暂无评论