溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

touchSwipe移動(dòng)端觸摸事件

發(fā)布時(shí)間:2020-06-10 07:55:47 來(lái)源:網(wǎng)絡(luò) 閱讀:1812 作者:kingbo66 欄目:web開發(fā)

今天分享一款很棒的插件touchSwipe,估計(jì)很多朋友都在找手機(jī)全屏滾動(dòng)的效果,因?yàn)楹枚嗥髽I(yè)的微官網(wǎng)是或是專題都在用這樣的效果,那么今天touchSwipe 1.6是最新的專門為移動(dòng)設(shè)備設(shè)計(jì)的jquery插件,如:Ipad,蘋果、安卓,當(dāng)然PC上也是可以用的,嘻嘻。插件touchSwipe可監(jiān)聽單個(gè)和多個(gè)手指觸摸,鼠標(biāo)按著左鍵拖動(dòng)等事件,因此插件可以實(shí)現(xiàn)滑動(dòng)滾屏、縮放等效果。本實(shí)例主講滾屏效果,相了解縮放功能的請(qǐng)參考官方文檔。

特點(diǎn):

1、監(jiān)聽滑動(dòng)的4個(gè)方向:上、下、左、右;

2、監(jiān)聽多個(gè)手指收縮還是外張;

3、支持單手指或雙手指觸摸事件;

4、支持單擊事件touchSwipe對(duì)象和它的子對(duì)象;

5、可定義臨界值和最大時(shí)間來(lái)判斷手勢(shì)的實(shí)際滑動(dòng);
6、滑動(dòng)事件有4個(gè)觸發(fā)點(diǎn):“開始”,“移動(dòng)”,“結(jié)束”和“取消”;

7、結(jié)束事件可以在手提釋放或是快速達(dá)到臨界值時(shí)觸發(fā);

8、允許手指刷和頁(yè)面滾屏;

9、可禁用戶通過(guò)輸入元素(如:按鈕、表單、文本框等)觸發(fā)事件;

引入核心文件

<script type="text/javascript" src="http://libs.useso.com/js/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.touchSwipe.min.js"></script>


寫入CSS文件

* { margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; }
.container { width: 100%; height: 100%; position: absolute; left: 0; top: 0%; }
.container .page { height: 100%; position: relative; color:#fff;text-align:center; }
.container .page h2{padding-top:120px; line-height:50px; color:#666;}
.container .page p{text-align:center; color:#aaa;}
.container .page0{background:url(p_w_picpaths/1.jpg) center center no-repeat;}
.container .page1{background:url(p_w_picpaths/2.jpg) center center no-repeat;}
.container .page2{background:url(p_w_picpaths/3.jpg) center center no-repeat;}
.container .page3{background:url(p_w_picpaths/4.jpg) center center no-repeat;}

寫入JS實(shí)現(xiàn)效果

  $(document).ready(
        function() {
            var nowpage = 0;
            //給class為container的容器加上觸滑監(jiān)聽事件
            $(".container").swipe(
                {
                    swipe:function(event, direction, distance, duration, fingerCount) {//事件,方向,距離(像素為單位),時(shí)間,手指數(shù)量
                         if(direction == "up")//當(dāng)向上滑動(dòng)手指時(shí)令當(dāng)前頁(yè)面記數(shù)器加1
                         {
                            nowpage = nowpage + 1;
                         }
                         else if(direction == "down")//當(dāng)向下滑動(dòng)手指時(shí)令當(dāng)前頁(yè)面記數(shù)器減1
                         {
                            nowpage = nowpage - 1;
                         }
 
                         if(nowpage > 4)//因本實(shí)例只有5張圖片,所以當(dāng)記數(shù)器大于4時(shí)令他返回4(從0開始記),避免溢出出錯(cuò)
                         {
                            nowpage = 4;
                         }
 
                         if(nowpage < 0)//道理同上
                         {
                            nowpage = 0;
                         }
                        $(".container").animate({"top":nowpage * -100 + "%"},400);//根據(jù)當(dāng)前記數(shù)器滾動(dòng)到相應(yīng)的高度
                    }
                }
            );
        }
    );


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI