【发布时间】:2014-02-28 18:14:49
【问题描述】:
如何在最后一张幻灯片上“向右滑动”以转到 URL? (就像在幻灯片 6 上单击“下一步”时一样)
http://nonoisenow.com/slideshow/
JS 代码: http://nonoisenow.com/jscode/swiperight.js
有什么建议吗? 谢谢!
【问题讨论】:
标签: jquery mobile anythingslider
如何在最后一张幻灯片上“向右滑动”以转到 URL? (就像在幻灯片 6 上单击“下一步”时一样)
http://nonoisenow.com/slideshow/
JS 代码: http://nonoisenow.com/jscode/swiperight.js
有什么建议吗? 谢谢!
【问题讨论】:
标签: jquery mobile anythingslider
如果我正确阅读了文档,您可以在jquery.anythingslider.js 文件中将“swipeleft”和“swiperight”添加到激活 clickForwardArrow 和 clickBackwardArrow 的事件列表中
这是用于交互的原始文件部分:
// Interactivity
clickForwardArrow : "click", // Event used to activate forward arrow functionality (e.g. add jQuery mobile's "swiperight")
clickBackArrow : "click", // Event used to activate back arrow functionality (e.g. add jQuery mobile's "swipeleft")
clickControls : "click focusin", // Events used to activate navigation control functionality
clickSlideshow : "click", // Event used to activate slideshow play/stop button
allowRapidChange : false, // If true, allow rapid changing of the active pane, instead of ignoring activity during animation
这是添加事件后的样子(我认为):
// Interactivity
clickForwardArrow : "click swiperight", // Event used to activate forward arrow functionality (e.g. add jQuery mobile's "swiperight")
clickBackArrow : "click swipeleft", // Event used to activate back arrow functionality (e.g. add jQuery mobile's "swipeleft")
clickControls : "click focusin", // Events used to activate navigation control functionality
clickSlideshow : "click", // Event used to activate slideshow play/stop button
allowRapidChange : false, // If true, allow rapid changing of the active pane, instead of ignoring activity during animation
【讨论】:
swiperight.js 而不是 jquery.anythingslider.js ?还是我错过了什么
修改滑动代码以检查滑动是否发生在最后一页,如果是,则转到所需的URL(demo)
if (newx < x) {
if (slider.currentPage < slider.pages) {
slider.goForward();
} else if (slider.currentPage === slider.pages) {
// swipe while on the last page will go to google
// doesn't work in this demo because of iframes
window.location.href = 'http://google.com';
}
}
这里是完整的代码:
/******************************************
Swipe Demo - without using jQuery Mobile
******************************************/
$('#slider').anythingSlider({
// 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';
$('<div class="swipe-overlay"></div>')
.appendTo(slider.$window)
.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 (slider.currentPage < slider.pages) {
slider.goForward();
} else if (slider.currentPage === slider.pages) {
// swipe while on the last page will go to google
// doesn't work in this demo because of iframes
window.location.href = 'http://google.com';
}
}
if (newx > x) { slider.goBack(); }
t = 0; x = 0;
}
});
}
});
【讨论】: