久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術文章
文章詳情頁

vue移動端寫的拖拽功能示例代碼

瀏覽:13日期:2022-11-25 18:00:21

相關知識點

touchstart 當在屏幕上按下手指時觸發touchmove 當在屏幕上移動手指時觸發touchend 當在屏幕上抬起手指時觸發mousedown mousemove mouseup對應的是PC端的事件touchcancel 當一些更高級別的事件發生的時候(如電話接入或者彈出信息)會取消當前的touch操作,即觸發 touchcancel。一般會在touchcancel時暫停游戲、存檔等操作。

效果圖

vue移動端寫的拖拽功能示例代碼

實現步驟html

總結了一下評論,好像發現大家都碰到了滑動的問題。就在這里提醒一下吧??蓪⒃搼腋?DIV 同你的 scroller web 同級。

<template><div id='webId'> <div>你的web頁面</div> <!-- 1.1 如果碰到滑動問題,請檢查這里是否屬于同一點。 --> <!-- 懸浮的HTML --> <div @mousedown='down()' @touchstart='down()' @mousemove.prevent.stop='move()' @touchmove.prevent.stop='move()' @mouseup='end()' @touchend='end()' > <div class='yuanqiu'>11</div> </div></div></template>

js

<script>data() { return { flags: false, position: { x: 0, y: 0 }, nx: ’’, ny: ’’, dx: ’’, dy: ’’, xPum: ’’, yPum: ’’, }}methods: { // 實現移動端拖拽 down(){ this.flags = true; let touch; if(event.touches){ touch = event.touches[0]; }else { touch = event; } this.position.x = touch.clientX; this.position.y = touch.clientY; this.dx = moveDiv.offsetLeft; this.dy = moveDiv.offsetTop; }, move(){ if(this.flags){ let touch ; if(event.touches){ touch = event.touches[0]; }else { touch = event; } this.nx = touch.clientX - this.position.x; this.ny = touch.clientY - this.position.y; this.xPum = this.dx+this.nx; this.yPum = this.dy+this.ny; //添加限制:只允許在屏幕內拖動 const maxWidth = document.body.clientWidth - 54;//屏幕寬度減去懸浮框寬高 const maxHeight = document.body.clientHeight - 54; if (this.xPum < 0) { //屏幕x限制this.xPum = 0; } else if (this.xPum>maxWidth) { this.xPum = maxWidth; } if (this.yPum < 0) { //屏幕y限制this.yPum = 0; } else if (this.yPum>maxHeight) {this.yPum = maxHeight; } moveDiv.style.left = this.xPum+'px'; moveDiv.style.top = this.yPum +'px'; //阻止頁面的滑動默認事件 document.addEventListener('touchmove',function(){ // 1.2 如果碰到滑動問題,請注意是否獲取到 touchmove event.preventDefault();//jq 阻止冒泡事件 // event.stopPropagation(); // 如果沒有引入jq 就用 stopPropagation() },false); } },//鼠標釋放時候的函數 end(){ this.flags = false; },}</script>

css

<style> /*css樣式可自定義 僅提供參考*/ #webId { position: relative; } .xuanfu { height: 54px; /* rem = 12px */ width: 54px; /*1.3 如果碰到滑動問題,請檢查 z-index。z-index需比web大一級*/ z-index: 999; position: fixed; top: 4.2rem; right: 3.2rem; border-radius: 0.8rem; background-color: rgba(0, 0, 0, 0.55); } .yuanqiu { height: 2.7rem; width: 2.7rem; border: 0.3rem solid rgba(140, 136, 136, 0.5); margin: 0.65rem auto; color: #000000; font-size: 1.6rem; line-height: 2.7rem; text-align: center; border-radius: 100%; background-color: #ffffff; }</style>

總結

到此這篇關于vue移動端寫的拖拽功能示例代碼的文章就介紹到這了,更多相關vue移動端拖拽內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Vue
相關文章:
主站蜘蛛池模板: 日本三级电影免费 | 亚洲成人精品在线 | 欧美不卡| 日本精品免费在线观看 | 欧美精品一区二区三区在线 | 欧美激情在线精品一区二区三区 | 久久久在线视频 | 国产精品久久久久久亚洲调教 | 亚洲成人av| 亚洲欧美国产毛片在线 | 欧美日韩精品综合 | 免费a大片| 亚洲一区二区三区爽爽爽爽爽 | 精品一区久久 | 国产a级毛片| 亚洲精品在线免费 | 国产一级片儿 | 日韩久色 | 午夜高清视频 | 亚洲综合色视频在线观看 | 国产二区视频 | 亚洲国产一区视频 | 一区二区久久 | 免费观看的av| 亚洲精品一区二区三区中文字幕 | 午夜免费福利视频 | 欧美精品一二三 | 国产精品久久久久久久久免费桃花 | 欧美不卡一区二区三区 | 91精品久久久久久久久 | 美女黄网| 一级在线播放 | 天天操天天摸天天干 | av男人的天堂在线 | 国产成人精品一区二区三区视频 | 久草免费福利 | 日韩欧美国产一区二区 | 亚洲精品免费观看 | 久久激情综合 | 毛片激情永久免费 | 国产一区二区三区在线视频 |