js 판단 이동단 제스처 상하좌우 미끄럼 이벤트

3102 단어


    
        
        
        <script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"/>
    
    
    
    
    <script type="text/javascript"><span style="color:#000000;">
    
$(</span>"body").on("touchstart", <span style="color:#0000ff;">function</span><span style="color:#000000;">(e) {
    e.preventDefault();
    startX </span>= e.originalEvent.changedTouches[0<span style="color:#000000;">].pageX,
    startY </span>= e.originalEvent.changedTouches[0<span style="color:#000000;">].pageY;
});
$(</span>"body").on("touchmove", <span style="color:#0000ff;">function</span><span style="color:#000000;">(e) {
    e.preventDefault();
    moveEndX </span>= e.originalEvent.changedTouches[0<span style="color:#000000;">].pageX,
    moveEndY </span>= e.originalEvent.changedTouches[0<span style="color:#000000;">].pageY,
    X </span>= moveEndX -<span style="color:#000000;"> startX,
    Y </span>= moveEndY -<span style="color:#000000;"> startY;
     
    </span><span style="color:#0000ff;">if</span> ( Math.abs(X) > Math.abs(Y) && X > 0<span style="color:#000000;"> ) {
        alert(</span>"left 2 right"<span style="color:#000000;">);
    }
    </span><span style="color:#0000ff;">else</span> <span style="color:#0000ff;">if</span> ( Math.abs(X) > Math.abs(Y) && X < 0<span style="color:#000000;"> ) {
        alert(</span>"right 2 left"<span style="color:#000000;">);
    }
    </span><span style="color:#0000ff;">else</span> <span style="color:#0000ff;">if</span> ( Math.abs(Y) > Math.abs(X) && Y > 0<span style="color:#000000;">) {
        alert(</span>"top 2 bottom"<span style="color:#000000;">);
    }
    </span><span style="color:#0000ff;">else</span> <span style="color:#0000ff;">if</span> ( Math.abs(Y) > Math.abs(X) && Y < 0<span style="color:#000000;"> ) {
        alert(</span>"bottom 2 top"<span style="color:#000000;">);
    }
    </span><span style="color:#0000ff;">else</span><span style="color:#000000;">{
        alert(</span>"just touch"<span style="color:#000000;">);
    }
});
    </span></script>
</code></pre> 
   </div> 
   <p> </p> 
  </div> 
  <p> :https://www.cnblogs.com/wenb/p/7514673.html</p> 
 </div> 
</div>
                            </div>
                        </div>

좋은 웹페이지 즐겨찾기