【问题标题】:"next" and "previous" buttons won't work in this touch slider plugin“下一个”和“上一个”按钮在此触摸滑块插件中不起作用
【发布时间】:2014-05-08 22:44:36
【问题描述】:

我正在使用 touchSlider 插件:http://www.mobilizetoday.com/freebies/touchslider/examples#ex-6

我将插件的这个确切部分集成到我的网站中(我正在做出响应)。用手指滑动效果很好,但按钮不起作用。这是我的网站:http://dev.ux-pm.com。要获取滑块所在的页面,只需将浏览器宽度减小到小于 480 像素,然后点击level 1 in detail(蓝色按钮)

HTML 代码:

<div class="gallery-holder">
            <div class="gallery" id="gallery3">
                <div class="holder">
                    <div class="list">
                        <div class="item">
                            <div class="ibox">
                                level1
                            </div>
                        </div>
                        <div class="item">
                            <div class="ibox">
                                level2
                            </div>
                        </div>
                        <div class="item">
                            <div class="ibox">
                                level3
                             </div>
                         </div>
                            </div>
                        </div>
                    </div>
                </div>
                <a href="#" class="prev">Prev item</a>
                <a href="#" class="next">Next Item</a>
                <span id="counter"></span>
            </div>
        </div>  

JS:

 $(document).ready(function(){

                    $('#gallery3').touchSlider({
                        mode: 'index',
                        center: true,
                        prevLink: 'a.prev',
                        nextLink: 'a.next',
                        onChange: function(prev, curr) {
                            $('#counter').html((curr+1)+'/'+ $('#gallery3').get(0).getCount());
                        },
                        onStart: function(){
                            $('#counter').html('1/' + $('#gallery3').get(0).getCount());
                        }
                    });
    });

CSS:

body {
    margin: 0;
    padding: 10px;
    font: 14px Helvetica, Arial, sans-serif;
    color: #666;
    max-width: 800px;
    min-width: 300px;
    margin: 0 auto;
}

h1, h2 {
    margin: 0;
    padding: 0 0 10px 0;
    font-size: 16px;
    color: #333;
}

.box {
    width: 96px;
    height: 96px;
    line-height: 96px;
    text-align: center;
    color: #FFF;
    margin: 2px;
    display: block;
    text-decoration: none;
    overflow: hidden;
    position: relative;
}

.box img {
    width: 96px;
    vertical-align: middle;
}

.box1 {background: red;}
.box2 {background: blue;}
.box3 {background: orange;}

.ibox,
.cbox,
.fbox {
    width: 210px;
    height: 210px;
    line-height: 210px;
    text-align: center;
    color: #FFF;
    margin: 2px;
    display: block;
    text-decoration: none;
    overflow: hidden;
    position: relative;
}

.centered .ibox,
.centered .cbox{
    margin: 2px auto;
    padding: 0 2px;
}


.ibox img {
    width: 210px;
    vertical-align: middle;
}

.cbox img,
.fbox img{
    width: 100%;
    vertical-align: middle;
}

.fbox {
    width: 600px;
    height: 600px;
    line-height: 600px;
}

span.delta {
    position: absolute;
    top: 0;
    width: 1px;
    text-indent: -9999px;
    overflow: hidden;
    background: magenta;
}

.ibox span.delta {
    height: 210px;
}

.active .box {
    outline: 1px dashed green;
}

.gallery-holder {
    margin: 0 auto;
    outline: 1px dashed #666;
    margin: 0 auto 10px auto;
    padding: 10px;
}

.gallery {
    width: 100%;
    overflow: hidden;
}

.gallery div.holder {
    width: 100%;
    position: relative;
    overflow: hidden;
}

.gallery div.list {
    margin: 0;
    padding: 0;
    list-style: none;
    width: 9999px;
    overflow: hidden;
}

.gallery div.item {
    float: left;
}

/*.moving {
    background: yellow;
}*/

.debug-item {
    padding: 1px 0;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    margin-bottom: -1px;
    color: #999;
    font-size: 11px;
}

#menu {
    margin: 0;
    padding: 0;
    list-style: none;
}

#menu a {
    display: block;
    border: 1px solid #ccc;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    padding: 6px 0;
    margin-bottom: 6px;
    font-size: 16px;
    color: #333;
    background: #EFEFEF;
    text-decoration: none;
    text-align: center;
}

a.prev,
a.next,
#moveTo,
a.tablink,
#counter {
    border: 1px solid #CCC;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    padding: 6px;
    margin-bottom: 6px;
    font-size: 16px;
    color: #333;
    background: #EFEFEF;
    text-decoration: none;
}
a.prev {float: left;}
a.next {float: right;}

#moveTo,
#counter {
    display: block;
    margin: 0 auto;
    overflow: hidden;
    width: 200px;
    text-align: center;
}

.focus .ibox {
    outline: 1px dashed green;
}
.focus-old .ibox {
    outline: 1px dashed red;
}

#tabs, #tabs2 {
    text-align: center;
}
.tablink {
    display: inline-block;
    overflow: hidden;
    width: 20px;
    height: 20px;
    text-align: center;
    margin: 0 2px;
}
a.active {
    border-color: #333;
}

#tabs2 .tablink {
    display: inline-block;
    overflow: hidden;
    width: 15px;
    height: 15px;
    text-align: center;
    margin: 0 10px;
    border-radius: 15px;
    -moz-border-radius: 15px;
    -webkit-border-radius: 15px;
    text-indent: -9999px;
}

#tabs2 a.active {
    background-color: #666;
}

我拼命地试图找出问题所在,但我找不到......有什么帮助吗?谢谢

【问题讨论】:

  • 我在实际页面上没有看到您的 JS 脚本。此外,您加载了两次 jQuery,这通常会导致问题。
  • Ralph 奇怪的是我的 js 加载了两次,我到处寻找可以加载两次的地方!知道为什么它会加载两次吗?
  • 我对 WP 不是很有经验,但可能是默认情况下有一个或多个附加组件将其放入其中。

标签: javascript jquery css plugins slider


【解决方案1】:

您的导航元素没有嵌套在 gallery3 中,这是插件期望它们所在的位置:

<div id="left2">
<div class="gallery-holder">
        <div class="gallery" id="gallery3">
            <div class="holder">
                <div class="list" style="transition: 0.5s ease; -webkit-transition: 0.5s ease; -webkit-transform: translate3d(60px, 0px, 0px);">
                    <div class="item active"></div>
                    <div class="item"></div>
                    <div class="item"></div>
                </div>
            </div>
        </div>
    </div>
<a href="#" class="prev">Prev item</a>
<a href="#" class="next">Next Item</a>
<span id="counter">1/3</span>

touchSlide 插件在按钮选择器的初始化对象范围内查找。 http://touchslider.com/

尝试将它们嵌套在gallery3 的一侧,而不是holder 的内部。

【讨论】:

  • lemieuxster 既然你已经知道这个插件,我遇到了另一个问题,滑块在 ios 上完美滑动,但在其他设备上非常糟糕,如 nexus 4 和 5、三星,可能还有其他设备。(他们支持chrome,这可能是问题)。然而,当我减小桌面浏览器的宽度时,它运行良好!我不知道为什么会这样。任何的想法?您可以在我的问题中看到指向该网站的链接。您可以直接跳转到“培训计划”部分查看。
  • @user3618369 我不知道为什么会有区别,除了插件如何使用浏览器事件以及如何触发这些事件。实际上,查看代码,它似乎只在浏览器上使用触摸事件,它是 webkit,所以可能检测工作不正常。无论如何,我现在恐怕帮不上什么忙了。
猜你喜欢
  • 1970-01-01
  • 2020-05-30
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
  • 2013-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多