当前位置:网站首页>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
边栏推荐
- [learning] database: several cases of index failure
- 求组合数 AcWing 887. 求组合数 III
- Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter
- MySQL advanced part 1: View
- Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
- New title of module a of "PanYun Cup" secondary vocational network security skills competition
- H5内嵌App适配暗黑模式
- Find the combination number acwing 889 01 sequence meeting conditions
- Records of some tools 2022
- Game theory acwing 891 Nim games
猜你喜欢

4. 对象映射 - Mapping.Mapster

求组合数 AcWing 889. 满足条件的01序列

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

Client use of Argo CD installation

ollvm编译出现的问题纪录

Find the combination number acwing 888 Find the combination number IV

4.Oracle-重做日志文件管理

区间问题 AcWing 906. 区间分组

Chinese remainder theorem acwing 204 Strange way of expressing integers

Bit of MySQL_ OR、BIT_ Count function
随机推荐
Chart. JS - Format Y axis - chart js - Formatting Y axis
MySQL advanced part 2: the use of indexes
【LeetCode】Easy | 20. Valid parentheses
2021apmcm post game Summary - edge detection
Basic explanation of typescript
LeetCode 1200. Minimum absolute difference
TypeScript入门
__ builtin_ Popcount() counts the number of 1s, which are commonly used in bit operations
Records of some tools 2022
4.Oracle-重做日志文件管理
Winter vacation water test 1 Summary
What's wrong with this paragraph that doesn't work? (unresolved)
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
TypeScript 基础讲解
Find the combination number acwing 889 01 sequence meeting conditions
AE tutorial - path growth animation
International Open Source firmware Foundation (osff) organization
Game theory acwing 893 Set Nim game
在新线程中使用Handler
[BMZCTF-pwn] ectf-2014 seddit