当前位置:网站首页>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
边栏推荐
- Sum of three terms (construction)
- 安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel
- Dataframe (1): introduction and creation of dataframe
- MySQL advanced part 2: MySQL architecture
- There are three kinds of SQL connections: internal connection, external connection and cross connection
- 5.Oracle-表空间
- Inclusion exclusion principle acwing 890 Divisible number
- LeetCode 0107. Sequence traversal of binary tree II - another method
- One question per day 1020 Number of enclaves
- Usage scenarios of golang context
猜你喜欢
MySQL advanced part 1: index
博弈论 AcWing 894. 拆分-Nim游戏
P2575 master fight
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
WordPress switches the page, and the domain name changes back to the IP address
5.Oracle-表空间
什么是套接字?Socket基本介绍
Paper reading report
MySQL advanced part 2: MySQL architecture
2.Oracle-数据文件的添加及管理
随机推荐
MPLS experiment
4.Oracle-重做日志文件管理
Chinese remainder theorem acwing 204 Strange way of expressing integers
MySQL advanced part 2: storage engine
2048 project realization
How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
高斯消元 AcWing 884. 高斯消元解异或線性方程組
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
[leetcode] day94 reshape matrix
[BMZCTF-pwn] ectf-2014 seddit
LeetCode-61
Game theory acwing 892 Steps Nim game
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
Redis-01.初识Redis
Leetcode-6110: number of incremental paths in the grid graph
中国剩余定理 AcWing 204. 表达整数的奇怪方式
Knapsack problem acwing 9 Group knapsack problem
Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
Operator priority, one catch, no doubt
1.14 - assembly line