需要Swipe.js getPos()和getNumSlides()帮助

时间:2013-05-16 01:32:31

标签: javascript jquery function plugins carousel

我目前正在使用Swipe.js(https://github.com/bradbirdsall/Swipe/blob/master/README.md)作为我用于网站的旋转木马。我对此有点新意,可以使用一些帮助。我的代码在下面,并在http://jsfiddle.net/eg5d2/1/保存了一个简短的样本,以使生活更轻松一些。谢谢!

滑动会显示一些可用于滑块脚本控制的功能。

prev()slide to prev

next()滑到下一个

getPos()返回当前幻灯片索引位置

getNumSlides()返回幻灯片的总数

slide(index,duration)slide以设置索引位置(duration:转换速度,以毫秒为单位)

                            <div id='mySwipe4' class='swipe'>
                            <div class='swipe-wrap'>
                                <div>
                                    <img src="activation-1.jpg" />
                                </div>
                                <div>
                                    <img src="activation-1.jpg" />
                                </div>
                                <div>
                                    <img src="activation-1.jpg" />
                                </div>
                                <div>
                                    <img src="activation-1.jpg" />
                                </div>
                            </div>
                        </div>
<div id="slide-indicators">INSERT SLIDE INIDCATOR HERE / TOTAL NUMBER OF SLIDES</div>
<script>
    window.mySwipe4 = new Swipe(document.getElementById('mySwipe4'), {
  continuous: true,
  disableScroll: false,
  stopPropagation: false

});
</script>

1 个答案:

答案 0 :(得分:0)

你走了。我删除了disableScrollstopPropagation值,因为默认情况下这些值为false。

<div id='mySwipe4' class='swipe'>
    <div class='swipe-wrap'>
        <div>
            <img src="activation-1.jpg">
        </div>
        <div>
            <img src="activation-1.jpg">
        </div>
        <div>
            <img src="activation-1.jpg">
        </div>
        <div>
            <img src="activation-1.jpg">
        </div>
    </div>
</div>

<div id="slide-indicators">1 / 1</div>

<script src="swipe.js"></script>
<script>
    // Variables
    var elem = document.getElementById('mySwipe4');
    var currentSlide = getPos() + 1; // because slide count starts at 0
    var totalSlides = getNumSlides();

    // Functions
    window.mySwipe = Swipe(elem, {
      continuous: true,
      callback: function(index, element) {
        document.getElementById('slide-indicators').innerHTML = currentSlides + ' / ' + totalSlides;
      }
    });
    document.getElementById('slide-indicators').innerHTML = currentSlides + ' / ' + totalSlides;
</script>