我正在尝试使用滑动事件在页面之间导航,这是我的代码
$( document ).on( "swipeleft", page, function() {
$.mobile.changePage( "#"+next, { transition: "slide" },false );
}); // Navigate to next page when the "next" button is clicked
$( ".control .next", page ).on( "click", function() {
$.mobile.changePage( "#"+next, { transition: "slide" },false );
});
但是滑动在Android设备上无法正常工作,任何帮助都将受到高度赞赏
提前致谢
答案 0 :(得分:1)
这将是开始滑动 (
function( event ) {
var data = event.originalEvent.touches ?
event.originalEvent.touches[ 0 ] : event;
return {
time: ( new Date() ).getTime(),
coords: [ data.pageX, data.pageY ],
origin: $( event.target )
};
}
)
滑动停止的时间 (
function( event ) {
var data = event.originalEvent.touches ?
event.originalEvent.touches[ 0 ] : event;
return {
time: ( new Date() ).getTime(),
coords: [ data.pageX, data.pageY ]
};
}
)
此方法接收开始和停止对象,并处理滑动事件的逻辑和触发。
(
function( start, stop ) {
if ( stop.time - start.time < $.event.special.swipe.durationThreshold &&
Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.horizontalDistanceThreshold &&
Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < $.event.special.swipe.verticalDistanceThreshold ) {
start.origin.trigger( "swipe" )
.trigger( start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight" );
}
}
)
HTMl代码 (
<script>
$(function(){
// Bind the swipeHandler callback function to the swipe event on div.box
$( "div.box" ).on( "swipe", swipeHandler );
// Callback function references the event target and adds the 'swipe' class to it
function swipeHandler( event ){
$( event.target ).addClass( "swipe" );
}
});
</script>
)
答案 1 :(得分:0)
你可以试试这个:
$.mobile.changePage( "#"+next, { transition: "slide" },false );
//----------put changehash inside this--------------^^--^^^^
到此:
$.mobile.changePage( "#"+next, { transition: "slide", changeHash: false });