添加jquery移动滑动事件
我有一个listview,我想要做的是在链接上添加一个滑动事件。 例如,如果用户滑动第一个链接,则会转到该页面。 这可能与listview元素一起使用。 我试过div,href,a,li,ul但仍然没有警报。 它适用于身体。 谢谢
$("div ul li.rqstpage").bind('swipe',function(event, ui){ $.mobile.changePage("requests.php", "slide"); });
实例:
JS:
$("#listitem").swiperight(function() { $.mobile.changePage("#page1"); });
HTML:
- Swipe Right to view Page 1
- Navigation
- Back to the Home Page
Yeah!
You Swiped Right to view Page 1
有关:
- 将JQM滑动事件添加到listview链接
您是否尝试过使用live()
绑定?
更新 : .live()
将被弃用,正确的用法是.on()
它将处理程序附加到所有当前匹配元素的事件以及稍后可能匹配的元素。
pageCreate() { $(parent).on('swipe', 'li.rqstpage', function() { $.mobile.changePage("requests.php", "slide"); } }
您是否考虑过使用此库进行手势 ?
它是否可以直接在控件上绑定它,如下所示:
pageCreate() { $("li.rqstpage").swipe() { $.mobile.changePage("requests.php", "slide"); } }
如果您希望页面在用户滑动的自然方向上滑动,则执行以下操作:
// For a left swipe: page slides from right to left $('#listitem').on('swipeleft', function() { $.mobile.changePage('#page-to-left', { transition: slide}); }); // For a right swipe: page slides from left to right (add "reverse: true") $('#listitem').on('swiperight', function() { $.mobile.changePage('#page-to-right', { transition: slide, reverse: true}); });
如果你想要转换,你需要指定你想要转换,例如
$.mobile.changePage('#page1', { transition: 'flip' });