javascript - Jquery 选项卡与旋转 slider 冲突

标签 javascript jquery tabs conflict

我正在尝试创建一个包含旋转 slider 和选项卡脚本的页面。

您可以在这里找到该页面:http://lovebomb.nl/dating

但不知何故,这些脚本相互冲突。

这部分的转数 slider :

        var tpj=jQuery;
    tpj.noConflict();

    tpj(document).ready(function() {

    if (tpj.fn.cssOriginal!=undefined)
        tpj.fn.css = tpj.fn.cssOriginal;

        tpj('.fullwidthbanner').revolution(
            {
                delay:9000,
                startwidth:1024,
                startheight:616,
                onHoverStop:"on",                       // Stop Banner Timet at Hover on Slide on/off
                thumbWidth:100,                         // Thumb With and Height and Amount (only if navigation Tyope set to thumb !)
                thumbHeight:50,
                thumbAmount:3,
                navigationStyle:"round",                // round,square,navbar,round-old,square-old,navbar-old, or any from the list in the docu (choose between 50+ different item), custom
                navigationHAlign:"center",              // Vertical Align top,center,bottom
                navigationVAlign:"top",                 // Horizontal Align left,center,right
                navigationHOffset:0,    
                navigationVOffset:20,
                soloArrowLeftHalign:"left",
                soloArrowLeftValign:"center",
                soloArrowLeftHOffset:20,
                soloArrowLeftVOffset:0,
                soloArrowRightHalign:"right",
                soloArrowRightValign:"center",
                soloArrowRightHOffset:20,
                soloArrowRightVOffset:0,
                touchenabled:"off",                     // Enable Swipe Function : on/off
                stopAtSlide:1,                          // Stop Timer if Slide "x" has been Reached. If stopAfterLoops set to 0, then it stops already in the first Loop at slide X which defined. -1 means do not stop at any slide. stopAfterLoops has no sinn in this case.
                stopAfterLoops:0,                       // Stop Timer if All slides has been played "x" times. IT will stop at THe slide which is defined via stopAtSlide:x, if set to -1 slide never stop automatic
                hideCaptionAtLimit:0,                   // It Defines if a caption should be shown under a Screen Resolution ( Basod on The Width of Browser)
                hideAllCaptionAtLilmit:0,               // Hide all The Captions if Width of Browser is less then this value
                hideSliderAtLimit:0,                    // Hide the whole slider, and stop also functions if Width of Browser is less than this value
                fullWidth:"on",
                shadow:0                                //0 = no Shadow, 1,2,3 = 3 Different Art of Shadows -  (No Shadow in Fullwidth Version !)
            });
 });

似乎与选项卡脚本的这部分冲突:

$(document).ready(function(){
$('#tabs div').hide();
$('#tabs div:first').show();
$('#tabs ul li:first').addClass('active');
$('#tabs ul li a').click(function(){ 
$('#tabs ul li').removeClass('active');
$(this).parent().addClass('active'); 
var currentTab = $(this).attr('href'); 
$('#tabs div').hide();
$(currentTab).show();
return false;
});
});

这些脚本合并在一个 JS 文件中,可以在此处找到:http://lovebomb.nl/dating/tabs.js

我使用此站点作为选项卡脚本的基础:http://www.snelgeldonlineverdienen.nl/

唯一的区别是 jquery 和 jquery UI 版本。 如果我使用本页的jquery版本,旋转 slider 将不再工作。

我已经尝试修复标签大约 4 个小时。

确实需要一些帮助。

提前致谢:)

卢克

最佳答案

tabs.js开头我们有声明:

var tpj=jQuery;
tpj.noConflict();

这将变量tpj设置为jQuery对象,然后将jQuery放入noConflict() :

"Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. If you need to use another JavaScript library alongside jQuery, return control of $ back to the other library with a call to $.noConflict()."

现在 jQuery 处于无冲突模式,您不能再使用 $ 访问 jQuery。所以当我们运行tabs.js底部的代码时:

$(document).ready(function(){
    $('#tabs div').hide();
    $('#tabs div:first').show();
    $('#tabs ul li:first').addClass('active');
    $('#tabs ul li a').click(function(){ 
    $('#tabs ul li').removeClass('active');
    $(this).parent().addClass('active'); 
    var currentTab = $(this).attr('href'); 
    $('#tabs div').hide();
    $(currentTab).show();
        return false;
    });
});

我们收到错误

"Uncaught TypeError: Property '$' of object [object Object] is not a function"

因为$不再引用jQuery。要访问 jQuery,我们必须使用 jQuerytpj

如果我们更改 tabs.js 将 $ 更改为 jQuerytpj

tpj(document).ready(function(){
    tpj('#tabs div').hide();
    tpj('#tabs div:first').show();
    tpj('#tabs ul li:first').addClass('active');
    tpj('#tabs ul li a').click(function(){ 
    tpj('#tabs ul li').removeClass('active');
    tpj(this).parent().addClass('active'); 
    var currentTab = tpj(this).attr('href'); 
    tpj('#tabs div').hide();
    tpj(currentTab).show();
        return false;
    });
});

代码应该正确执行。

关于javascript - Jquery 选项卡与旋转 slider 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16067465/

相关文章:

javascript - 如何在 jQuery 中切换图像的淡入/淡出效果?

javascript - jquery 实时点击事件在 IE8 中不起作用

javascript - 单击另一个选项卡中触发输入聚焦的按钮时动态更改选项卡事件

language-agnostic - 在Firefox中打开一个新标签页,并将ff保留在后台

javascript - FFMPEG 需要 3 分钟生成缩略图

javascript - 针对多个值过滤对象,仅返回完美匹配

javascript - 如何根据优先级对不同类型的数据进行排序?

javascript - 通过添加和删除类来实现 CSS 过渡

javascript - 如何将此 div 移动到 Bootstrap 导航栏上方?

javascript - 在基于 css 的选项卡结构中打开特定选项卡