我目前正在使用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>
答案 0 :(得分:0)
你走了。我删除了disableScroll
和stopPropagation
值,因为默认情况下这些值为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>