当前位置:网站首页>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
边栏推荐
- Find the combination number acwing 888 Find the combination number IV
- LeetCode-61
- 时间很快,请多做有意义的事情
- Stack acwing 3302 Expression evaluation
- [moviepy] unable to find a solution for exe
- Inclusion exclusion principle acwing 890 Divisible number
- Leetcode stack related
- 容斥原理 AcWing 890. 能被整除的数
- Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
- 博弈论 AcWing 893. 集合-Nim游戏
猜你喜欢

P2575 master fight

WordPress switches the page, and the domain name changes back to the IP address

博弈论 AcWing 891. Nim游戏

阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长

安装OpenCV--conda建立虚拟环境并在jupyter中添加此环境的kernel

Inclusion exclusion principle acwing 890 Divisible number

vsCode创建自己的代码模板

Game theory acwing 893 Set Nim game

1.14 - assembly line

Find the combination number acwing 888 Find the combination number IV
随机推荐
Traversal of leetcode tree
论文阅读报告
‘mongoexport‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
Redis-02.Redis命令
[moviepy] unable to find a solution for exe
Paper reading report
What's wrong with this paragraph that doesn't work? (unresolved)
RecyclerView的应用
our solution
Sword finger offer II 058: schedule
New title of module a of "PanYun Cup" secondary vocational network security skills competition
Leetcode recursion
MySQL advanced part 2: SQL optimization
TypeScript 基础讲解
7.Oracle-表结构
Leetcode divide and conquer / dichotomy
2048 project realization
Interval problem acwing 906 Interval grouping
Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
Ffmpeg build download (including old version)