当前位置:网站首页>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
边栏推荐
- Client use of Argo CD installation
- 3.Oracle-控制文件的管理
- LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively
- [learning] database: several cases of index failure
- Simple selection sort of selection sort
- Day 2 document
- [moviepy] unable to find a solution for exe
- NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
- New title of module a of "PanYun Cup" secondary vocational network security skills competition
- 2048项目实现
猜你喜欢

LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively

Find the combination number acwing 889 01 sequence meeting conditions

1.手动创建Oracle数据库

Leetcode array operation

Paper reading report
![[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian](/img/f1/e7a8a1a31bc5712d9f32d91305a2b0.jpg)
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian

MySQL advanced part 2: optimizing SQL steps

Day 2 document

3. Oracle control file management

阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长
随机推荐
求组合数 AcWing 887. 求组合数 III
【LeetCode】Easy | 20. Valid parentheses
confidential! Netease employee data analysis internal training course, white whoring! (attach a data package worth 399 yuan)
博弈论 AcWing 893. 集合-Nim游戏
Game theory acwing 894 Split Nim game
Leetcode-6111: spiral matrix IV
Game theory acwing 892 Steps Nim game
Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
Chart. JS - Format Y axis - chart js - Formatting Y axis
3.Oracle-控制文件的管理
Knapsack problem acwing 9 Group knapsack problem
Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
Leetcode-3: Longest substring without repeated characters
栈 AcWing 3302. 表达式求值
P3265 [jloi2015] equipment purchase
Leetcode backtracking method
P2575 master fight
What is socket? Basic introduction to socket
[wustctf2020] plain_ WP
Leetcode dynamic programming