下面的代碼添加了Android/iPad等觸摸導航。它將滑動導航添加到幻燈片縮略圖。這項功能非常出色,但縮略圖無法通過觸摸在平板電腦上進行點擊。您可以點擊他們在PC和滑塊會更改爲相應的幻燈片......不是在平板電腦上,它彷彿觸摸或「點擊」不執行任何操作(刷卡正常工作)jquery觸摸導航
JS小提琴
http://jsfiddle.net/Mottie/VM8XG/5165/
JS
$('#slider').anythingSlider({
navigationSize : 3,
// Callback when the plugin finished initializing
onInitialized: function(e, slider) {
var time = 1000, // allow movement if < 1000 ms (1 sec)
range = 50, // swipe movement of 50 pixels triggers the slider
x = 0, t = 0, touch = "ontouchend" in document,
st = (touch) ? 'touchstart' : 'mousedown',
mv = (touch) ? 'touchmove' : 'mousemove',
en = (touch) ? 'touchend' : 'mouseup';
slider.$window.add(slider.$controls)
.bind(st, function(e){
// prevent image drag (Firefox)
e.preventDefault();
t = (new Date()).getTime();
x = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
})
.bind(en, function(e){
t = 0; x = 0;
})
.bind(mv, function(e){
e.preventDefault();
var newx = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
r = (x === 0) ? 0 : Math.abs(newx - x),
// allow if movement < 1 sec
ct = (new Date()).getTime();
if (t !== 0 && ct - t < time && r > range) {
if (newx < x) {
if ($(this).hasClass('anythingControls')) {
slider.$controls.find('.next').trigger('click');
} else {
slider.goForward();
}
return false;
}
if (newx > x) {
if ($(this).hasClass('anythingControls')) {
slider.$controls.find('.prev').trigger('click');
} else {
slider.goBack();
}
}
t = 0; x = 0;
return false;
}
});
}
});