jQuery没有冲突不起作用 [英] Jquery no conflict not working

查看:105
本文介绍了jQuery没有冲突不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有点像两个问题.我正在尝试使用无冲突的jQuery,但我认为我做的不正确.

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.

这是我所拥有的:

// * ** * ** * ** * ** * ** * 插件 * ** * ** * ** * ** * ** *

// **************** 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?

此外,当我添加此代码时,它会使所有内容停止运行,这就是为什么我认为我没有正确添加no冲突的原因:

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' });
    }
});

谢谢.

推荐答案

您必须将jQuery传递给您的函数:

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?

这篇关于jQuery没有冲突不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆