Я новичок в phonegap. Я создаю приложение в eclipse, используя phonegap для Android. Я добавил телефон gap.jar и плагин в папку xml. Я также добавил библиотеку jquery и phonegap1.1.0 js. Я пытаюсь реализовать функцию прокрутки для перехода с одной страницы на другую, но она не работает. Кто-нибудь может сказать, как решить проблему?
Я вызываю inex.html в своей деятельности, это мой index.html
<html>
<head>
<title>sample check</title>
<link rel="stylesheet" href="www/jquery.mobile/jquery.mobile-1.0rc2.min.css" type="text/css" charset="utf-8" />
<script type="text/javascript" src="js/fnswipe.js"></script>
<script type="text/javascript" src="www/jquery.mobile/jquery-1.6.4.min"></script>
<script type="text/javascript" src="www/jquery.mobile/jquery.mobile-1.0rc2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
</head>
<body>
<div data-role="page" id="home">
<div data-role="content">
<p>
<ul data-role="listview" data-inset="true" data-theme="c">
<li id="listitem">Swipe Right to smple check page</li>
</ul>
</p>
</div>
</div>
</body>
</html>
Это мой файл js включен
$("#listitem").swiperight(function() {
$.mobile.changePage("file:///android_asset/www/samplecheck.html");
});
Спасибо за вашу помощь
Ответ 1 · рейтинг 3 · William Delong
У меня была такая же проблема, все события смахивания работали, кроме Android. Чтобы решить эту проблему, мне пришлось установить пороговые значения для событий Swipe. Вы можете установить их непосредственно перед вызовом событий смахивания в файле JS. Для достижения наилучших результатов я установил:
$.event.special.swipe.scrollSupressionThreshold = 10; // More than this horizontal displacement, and we will suppress scrolling.
$.event.special.swipe.horizontalDistanceThreshold = 30; // Swipe horizontal displacement must be more than this.
$.event.special.swipe.durationThreshold = 500; // More time than this, and it isn't a swipe.
$.event.special.swipe.verticalDistanceThreshold = 75; // Swipe vertical displacement must be less than this.
Этот ответ мне очень помог: swipeleft/swiperight срабатывает во время вертикальной прокрутки в мобильном jquery
А также документацию: События -> Touch Events -> Swipe а>
Надеюсь это поможет!!
Ответ 2 · рейтинг 1 · Community
Попробуйте код, похожий на этот, и посмотрите, поможет ли он каким-либо образом.
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 )
};
}
)
And the when the swipe stops (
function( event ) {
var data = event.originalEvent.touches ?
event.originalEvent.touches[ 0 ] : event;
return {
time: ( new Date() ).getTime(),
coords: [ data.pageX, data.pageY ]
};
}
)
This method receives the start and stop objects and handles the logic for and triggering for the swipe events.
(
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 code (
<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>
Ответ 3 · user2270213
ты можешь попробовать это
$("#listitem").on("swiperight", function() {
$.mobile.changePage("file:///android_asset/www/samplecheck.html");
});
Ответ 4 · Pradip Kharbuja
Я использую jquery mobile 1.2.0 для пролистывания страницы. Эта функция не зависит от phonegap или cordova. Это мой рабочий код. Надеюсь, что это поможет вам:
$(document).bind("pageinit", function(event) {
$('#page').unbind("swipeleft");
$("#next").unbind("swiperight");
$("#page").bind("swipeleft",function(event) {
$.mobile.changePage('next.html', {
transition : "slide"
});
});
$("#next").bind("swiperight",function(event) {
$.mobile.changePage('index.html', {
transition : "slide",
reverse : true
});
});
});