0
A
回答
2
您可以捕獲的地步「刷卡」開始然後跟蹤它的運動來決定做什麼:
$(document).on('vmousedown', function (event) {
//the swipe has started, get the starting point saved for later
$.data(this, 'swipe-start', { x : event.pageX, y : event.pageY });
}).on('vmouseup', function (event) {
//set the swipe-start date to null to we can start anew,
//this allows you to fire more than one control event with a single swipe,
//so long swipes trigger more control events than short ones
$.data(this, 'swipe-start', null);
}).on('vmousemove', function (event) {
if ($.data(this, 'swipe-start') != null) {
//here we can see how far the swipe has gone and in what direction
var distanceX = $.data(this, 'swipe-start').x - event.pageX,
distanceY = $.data(this, 'swipe-start').y - event.pageY,
distanceT = Math.sqrt(Math.pow(Math.abs($.data(this, 'swipe-start').x - event.pageX), 2) + Math.pow(Math.abs($.data(this, 'swipe-start').y - event.pageY), 2));
//let the user swipe at least 50 pixels before deciding what to do
if (distanceT > 50) {
if (distanceX > 0 && distanceY > 0) {
//user went up and to the right
$('.ui-content').append('<p>You went up/left</p>');
} else if (distanceX < 0 && distanceY > 0) {
//user went up and to the left
$('.ui-content').append('<p>You went up/right</p>');
} else if (distanceX < 0 && distanceY < 0) {
//user went down and to the left
$('.ui-content').append('<p>You went down/right</p>');
} else {
//user went down and to the right
$('.ui-content').append('<p>You went down/left</p>');
}
//reset the 'swipe-start' incase the user keeps swiping
$.data(this, 'swipe-start', { x : event.pageX, y : event.pageY });
}
}
});
然後適當if/then
語句中您將控制你的UI元素的代碼。
請注意,vmousedown
/vmouseup
/vmousemove
是jQuery Mobile自定義事件,旨在用於鼠標和觸摸輸入。
更新
我更新了上面的代碼有點更人性化,也有一對夫婦的問題,我不得不鍛鍊。這裏是一個工作演示:http://jsfiddle.net/sRxFC/1/
請注意,如果你想涉及動量,你還需要跟蹤滑動的速度來確定速度,而不僅僅是方向。
0
如果你想定製scrollpaths然後this jQuery plugin可以幫助你......如果你「只是」想顯示迂迴一會兒,然後滾動我會建議觀察通過JS的滾動事件,並通過CSS做一些轉變
還是我完全誤解了你?
+0
完全不相干的問題(這想添加滾動動量),但什麼是偉大的鏈接。乾杯:) – 2013-08-28 08:43:32
0
我在試用jQuery插件環形交叉口時遇到了這個問題。如果你想要的東西近在眼前,它只是起作用,我強烈推薦插件,並且它可以通過enableDrag屬性支持拖/刷。我只在iOS設備上進行了測試,但它在那裏效果很好,我想它可以在其他觸摸平臺上使用。
相關問題
- 1. Trigger.IO勢頭滾動
- 2. 迂迴jQuery插件按鍵箭頭鍵向左移動
- 3. Core Plot勢頭滾動
- 4. 迂迴DrawText
- 5. 點擊滾動勢頭是越野車
- 6. jquery應用慣性拖動勢頭
- 7. jquery accordion - 滾動到標頭
- 8. 迂迴路徑遍歷器
- 9. 在移動設備上滾動的勢頭
- 10. 移動Safari滾動勢頭不起作用
- 11. 在javascript中移除滾動條上的勢頭
- 12. 在iOS中溢出的一個手指勢頭滾動div
- 13. jquery標籤菜單滾動箭頭
- 14. JQuery Datatable頭部下方的滾動條
- 15. jQuery滾動使粘頭部分跳轉
- 16. jQuery頭部滾動,如何抵消?
- 17. 使這些箭頭滾動? jquery&html
- 18. Jquery iPhone/Android的滾動固定頭?
- 19. 水平滾動Jquery的隱藏/顯示滾動箭頭
- 20. 帶iframe視頻的迂迴滑塊javascript
- 21. MS Detours Library,迂迴非贏api函數
- 22. jquery自動滾動回查看
- 23. 滑動菜單手勢將覆蓋圖形手勢的可滾動手勢 - android
- 24. 滾動頭時滾動recyclerview項
- 25. 如何忽略外部庫頭中的gcc編譯器迂迴錯誤?
- 26. 滾動來回滾動到
- 27. 添加手勢識別器,以滾動垂直滾動瀏覽
- 28. 禁用通過手勢滾動滾動視圖
- 29. jquery動畫回滾到原始位置向下滾動(?)
- 30. UIScrollView在滾動時取消UIPageViewController手勢
謝謝!我試圖在用戶滑動時實時移動一個圖形,我想稍微修改一下會讓我這樣做。 – Akshat 2012-04-22 20:08:14
是的,只需將最小距離改爲非常低的值即可。 – Jasper 2012-04-22 20:41:09