jQuery如何實現(xiàn)觸摸事件

這篇文章主要為大家展示了“jQuery如何實現(xiàn)觸摸事件”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“jQuery如何實現(xiàn)觸摸事件”這篇文章吧。

專注于為中小企業(yè)提供成都網(wǎng)站制作、成都網(wǎng)站建設服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)井研免費做網(wǎng)站提供優(yōu)質(zhì)的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了近千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。

觸摸事件

// Define some variables
var ball = $('<div id="ball"></div>').appendTo('body'),
startPosition = {}, elementPosition = {};
// Listen for mouse and touch events
ball.on('mousedown touchstart',function(e){
  e.preventDefault();
  // Normalizing the touch event object
  e = (e.originalEvent.touches) ? e.originalEvent.touches[0] : e;
  // Recording current positions
  startPosition = {x: e.pageX, y: e.pageY};
  elementPosition = {x: ball.offset().left, y: ball.offset().top};
  // These event listeners will be removed later
  ball.on('mousemove.rem touchmove.rem',function(e){
    e = (e.originalEvent.touches) ? e.originalEvent.touches[0] : e;
    ball.css({
      top:elementPosition.y + (e.pageY - startPosition.y),
      left: elementPosition.x + (e.pageX - startPosition.x),
    });
  });
});
ball.on('mouseup touchend',function(){
  // Removing the heavy *move listeners
  ball.off('.rem');
});

以上是“jQuery如何實現(xiàn)觸摸事件”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)頁題目:jQuery如何實現(xiàn)觸摸事件
文章出自:http://muchs.cn/article30/pdphpo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航ChatGPT、動態(tài)網(wǎng)站、App開發(fā)、定制網(wǎng)站、搜索引擎優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務器托管