DIV CSS 佈局教程網

快速解決 jquery.touchSwipe 左右滑動與垂直捲軸衝突
編輯:關於JavaScript     

本文分享 jquery.touchSwipe 左右滑動與垂直捲軸衝突問題的解決方法,具體內容如下。

正好需要用 HTML5 做一個可以左右切換、但又要保留上下捲軸的功能。我在行動端用的是 jquery.touchSwipe 插件,上網找了好久都沒看到對應的解法,只好自己改,最後總算能用了。

先上張圖:

解決方式是:我把左右滑動的事件掛在 body 上,而上下滑動則改用 div 的垂直捲動。上程式碼:

 $("#body").swipe( { fingers:'all', swipeLeft:swipe1, swipeRight:swipe2} ); function swipe1(event, direction, distance, duration, fingerCount) { tab_shipu(-1); //向左滑動你要執行的動作 } function swipe2(event, direction, distance, duration, fingerCount) { tab_shipu(1); //向右滑動你要執行的動作 } 

上下捲軸則設定 div 的捲動;

 <div id="cook" class="cook"></div> <style> .cook{ overflow: auto; } </style> 

設定 body 和 div 預設高度的程式碼:

 $("body").css("height",document.body.scrollHeight); $(".cook").css("height",document.body.scrollHeight-$('#cook').position().top);

以上就是解決左右滑動與垂直捲軸衝突的方法,希望對大家的學習有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved