当前位置:网站首页>H5 module suspension drag effect
H5 module suspension drag effect
2022-07-05 06:26:00 【Heerey525】
problem : In mobile terminal H5 Suspending a module may block other contents , So you need to drag the suspended module .
programme : It's monitoring touch events ,( Absolute positioning ) Change the position of the module
Preview requires the browser to be in mobile mode
Code :
<template>
<div class="container">
<div class="floatBox" id="floatBox"></div>
</div>
</template>
<script>
export default {
name: 'touchMove',
data() {
return {
} },
mounted() {
this.touchMoveEvent()
},
methods: {
// The end consultation button allows dragging
touchMoveEvent() {
// Get elements
var div1 = document.getElementById('floatBox');
// var div1 = document.querySelector('#div1');
// Limit maximum width and height , Don't let the slider out
var maxW = document.body.clientWidth - div1.offsetWidth;
var maxH = document.body.clientHeight - div1.offsetHeight;
var oL, oT;
// Finger touch begins , Record div Initial position
div1.addEventListener('touchstart', function(e) {
var ev = e || window.event;
var touch = ev.targetTouches[0];
oL = touch.clientX - div1.offsetLeft;
oT = touch.clientY - div1.offsetTop;
document.addEventListener("touchmove", defaultEvent, false);
});
// In touch , Location record
div1.addEventListener('touchmove', function(e) {
var ev = e || window.event;
var touch = ev.targetTouches[0];
var oLeft = touch.clientX - oL;
var oTop = touch.clientY - oT;
if(oLeft < 0) {
oLeft = 0;
} else if(oLeft >= maxW) {
oLeft = maxW;
}
if(oTop < 75) {
oTop = 75;
} else if(oTop >= maxH - 75) {
oTop = maxH - 75;
}
div1.style.left = oLeft + 'px';
div1.style.top = oTop + 'px';
});
// Processing at the end of touch
div1.addEventListener('touchend', function() {
document.removeEventListener("touchmove", defaultEvent);
});
// Block default events
function defaultEvent(e) {
e.preventDefault();
}
}
}
}
</script>
<style>
.container {
width: 100vw;
height: 100vh;
background: black
}
.floatBox {
width: 100%;
position: fixed;
bottom: 140px;
right: 2%;
width: 80px;
height: 80px;
z-index: 11;
touch-action: none;
background: red;
}
</style>
Reference material :javascript Realize the touch screen drag function on the mobile terminal
边栏推荐
- 3. Oracle control file management
- 4. Oracle redo log file management
- 2022/6/29-日报
- Records of some tools 2022
- [QT] QT multithreading development qthread
- Leetcode stack related
- LeetCode-61
- Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
- 5. Oracle tablespace
- TCP's understanding of three handshakes and four waves
猜你喜欢
MPLS experiment
Quickly use Amazon memorydb and build your own redis memory database
博弈论 AcWing 893. 集合-Nim游戏
Game theory acwing 892 Steps Nim game
ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
将webApp或者H5页面打包成App
Leetcode-6108: decrypt messages
LeetCode-54
安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
高斯消元 AcWing 884. 高斯消元解异或线性方程组
随机推荐
2022-5-the fourth week daily
Redis-01.初识Redis
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian
Winter messenger 2
One question per day 1020 Number of enclaves
Winter vacation water test 1 Summary
MySQL advanced part 2: optimizing SQL steps
International Open Source firmware Foundation (osff) organization
Find the combination number acwing 889 01 sequence meeting conditions
高斯消元 AcWing 884. 高斯消元解异或線性方程組
Daily question 1189 Maximum number of "balloons"
SQL三种连接:内连接、外连接、交叉连接
Leetcode-6110: number of incremental paths in the grid graph
H5 模块悬浮拖动效果
Records of some tools 2022
1.15 - input and output system
【高德地图POI踩坑】AMap.PlaceSearch无法使用
Game theory acwing 891 Nim games
our solution
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations