简体   繁体   English

Javascript水平滑块不起作用

[英]Javascript horizontal slider not working

I'm using an old version of the Slidedeck Plugin (v.1.4.5) and I have a javascript problem with one of the skins I'm using. 我正在使用旧版本的Slidedeck插件(v.1.4.5),并且我使用的一种皮肤遇到了JavaScript问题。 More precisely, the horizontal slides are stitched together and I can't figure out how to fix this. 更准确地说,水平滑轨是缝合在一起的,我不知道该如何解决。 I want each slide to be independent, without any content from the next or previous slide to be seen on the active slide. 我希望每个幻灯片都是独立的,而下一个或上一个幻灯片的任何内容都不会在活动幻灯片上显示。

You can see in the screenshot from below that the middle slide has visible content from the previous and next slide, which obviously I don't want to be visible. 您可以从下面的屏幕截图中看到,中间的幻灯片具有上一张和下一张幻灯片的可见内容,显然我不希望看到该内容。

在此处输入图片说明

I should mention that I have very limited knowledge of javascript / jQuery, and I suspect it's a js problem because the CSS is the same for all skins - the only variable is the script used by each skin. 我应该提及的是,我对javascript / jQuery的了解非常有限,并且我怀疑这是一个js问题,因为所有皮肤的CSS都是相同的-唯一的变量是每个皮肤使用的脚本。

You can see the slider behavior on this website and below is the full script used for the slider skin. 您可以在此网站上看到滑块行为,下面是用于滑块皮肤的完整脚本。 I would appreciate any help on this. 我将不胜感激。 To change the slides click on each slide arrow from left or right side, or you can use the directional keys on the keyboard. 要更改幻灯片,请从左侧或右侧单击每个幻灯片箭头,或者可以使用键盘上的方向键。

(function($){
SlideDeckSkin['fullwidth-sexy'] = function(slidedeck){
    var ns = 'fullwidth-sexy';
    var elems = {};
        elems.slidedeck = $(slidedeck);
        elems.frame = elems.slidedeck.closest('.skin-' + ns);

    // Disable spines as this skin is not meant to function with spines on
    elems.slidedeck.slidedeck().setOption('hideSpines', true);

    elems.frame.append('<a href="#prev" class="sd-' + ns + '-nav prev">Previous</a><a href="#next" class="sd-' + ns + '-nav next">Next</a>');
    elems.slidedeck.append('<div class="' + ns + '-mask left"></div><div class="' + ns + '-mask right"></div>');

    elems.frame.find('.sd-' + ns + '-nav').bind('click', function(event){
        event.preventDefault();
        var $this = $(this);
        elems.slidedeck.slidedeck().options.pauseAutoPlay = true;
        if($this.hasClass('prev')){
            elems.slidedeck.slidedeck().prev();
        } else {
            elems.slidedeck.slidedeck().next();
        }
    });
};

$(document).ready(function(){
    $('.skin-fullwidth-sexy .slidedeck').each(function(){
        if(typeof($.data(this, 'skin-fullwidth-sexy')) == 'undefined' || $.data(this, 'skin-fullwidth-sexy') == null){
            $.data(this, 'skin-fullwidth-sexy', new SlideDeckSkin['fullwidth-sexy'](this));
        }
    });
});
})(jQuery);

The following might work, but it is hard to test without an example of what you are trying to do. 以下内容可能会起作用,但是如果没有您要尝试执行的示例,很难进行测试。

What I did is added a unique number to the ns variable (for namespace I assume.) This number is passed to the callback of the each function. 我所做的是在ns变量中添加了一个唯一的数字(我假设是命名空间。)此数字传递给每个函数的回调。 ( doc ) doc

(function($){
SlideDeckSkin['fullwidth-sexy'] = function(slidedeck,uniqueName){
    var ns = 'fullwidth-sexy'+uniqueName;
    var elems = {};
        elems.slidedeck = $(slidedeck);
        elems.frame = elems.slidedeck.closest('.skin-' + ns);

    // Disable spines as this skin is not meant to function with spines on
    elems.slidedeck.slidedeck().setOption('hideSpines', true);

    elems.frame.append('<a href="#prev" class="sd-' + ns + '-nav prev">Previous</a><a href="#next" class="sd-' + ns + '-nav next">Next</a>');
    elems.slidedeck.append('<div class="' + ns + '-mask left"></div><div class="' + ns + '-mask right"></div>');

    elems.frame.find('.sd-' + ns + '-nav').bind('click', function(event){
        event.preventDefault();
        var $this = $(this);
        elems.slidedeck.slidedeck().options.pauseAutoPlay = true;
        if($this.hasClass('prev')){
            elems.slidedeck.slidedeck().prev();
        } else {
            elems.slidedeck.slidedeck().next();
        }
    });
};

$(document).ready(function(){
    $('.skin-fullwidth-sexy .slidedeck').each(function(n){
        if(typeof($.data(this, 'skin-fullwidth-sexy')) == 'undefined' || $.data(this, 'skin-fullwidth-sexy') == null){
            $.data(this, 'skin-fullwidth-sexy', new SlideDeckSkin['fullwidth-sexy'+n](this,n));
        }
    });
});
})(jQuery);

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

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