In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to achieve wall-absorbing suspension ball by vue". In daily operation, I believe that many people have doubts about how to achieve wall-suction suspension ball in vue. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to achieve wall-suction suspension ball in vue". Next, please follow the editor to study!
1. Create a template, define customer service buttons, and customize v-drag instructions
Contact customer service
The 2.drag instruction mainly listens to the onmousedown, onmousemove and onmouseup events of el. In the onmouseup event, it determines whether to click or drag through the offset, and if it is drag and drop, it calculates the offset to determine which wall it is attached to.
Import chatDialog from ". / chatDialog"; export default {components: {chatDialog}, data () {return {dialogVisible: false,};}, mounted () {/ / initialize button position let clientW = document.documentElement.clientWidth; let clientH = document.documentElement.clientHeight; let div = document.getElementById ("btn"); div.style.top = clientH / 2 + "px"; div.style.left = clientW-80 + "px" }, methods: {openDialog () {this.dialogVisible = true;}, closeDialog () {this.dialogVisible = false;},}, directives: {drag (el, binding) {let oDiv = el; / / disable text on web pages _ document.onselectstart = function () {return false;} ODiv.onmousedown = function (e) {/ / Mouse press to calculate the distance of the current element from the visible area let disX = e.clientX-oDiv.offsetLeft; let disY = e.clientY-oDiv.offsetTop; / / record initial position let firstX = oDiv.offsetLeft; let firstY = oDiv.offsetTop; let l = oDiv.offsetLeft; let t = oDiv.offsetTop _ document.onmousemove = function (e) {/ / calculate the distance of movement l = e.clientX-disX; t = e.clientY-disY; / / move the current element oDiv.style.left = l + "px"; oDiv.style.top = t + "px";} _ document.onmouseup = function (e) {/ / Click event if (Math.abs (l-firstX))
< 3 || Math.abs(t - firstY) < 3) { binding.value.set(true); } else { // 拖拽事件 let clientW = document.documentElement.clientWidth; let clientH = document.documentElement.clientHeight; // 判断偏移量,并吸壁 // 垂直偏移量大于水平偏移量,左右吸壁,垂直控制范围 if (Math.abs(t - firstY) >Math.abs (l-firstX) {if (l > clientW / 2-80) {l = clientW-80;} else {l = 80;} if (t
< 40) t = 40; else if (t >ClientH-140) t = clientH-140;} else {/ / upper and lower suction wall, horizontal control range if (t > clientH / 2-140) {t = clientH-140;} else {t = 40;} if (l
< 80) l = 80; else if (l >ClientW-80) l = clientW-80;} oDiv.style.top = t + "px"; oDiv.style.left = l + "px";} _ document.onmousemove = null; _ document.onmouseup = null;} / / if return false is not added, it may lead to adhesion, that is, when div is dragged to a place, the mouse cannot be glued down, which is equivalent to onmouseup failure return false;};},},}.
3. Style setting z-index is always maintained at the top of the page, defining position positioning
.container {.btn {z-index: 9999; position: fixed; width: 40px; height: 130px; overflow: hidden; background: linear-gradient (210deg, # f3f5f8, # ffffff); border: 2px solid # ffffff; box-shadow: 3px 5px 10px 0px rgba (0,0,0,0.1); border-radius: 20px; text-align: center; img {margin: 5px 0; width: 30px; height: 30px } span {font-size: 14px; color: # 333333; cursor: pointer; font-family: PingFang SC;} at this point, the study of "how to achieve a wall-absorbing suspension ball by vue" is over. I hope it can solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.