This article example shares the specific code of Vue to realize the image drag and drop function for your reference. The specific content is as follows 1. Mainly involved element knowledge, schematic diagram: 2. js code part: directives: { drag: { // Definition of instruction bind: function(el) { // Get the current element let oDiv = el; oDiv.onmousedown = (e) => { // Calculate the position of the mouse relative to the element let disX = e.clientX - oDiv.offsetLeft; let disY = e.clientY - oDiv.offsetTop; document.onmousemove = (e) => { // Subtract the position of the mouse relative to the element from the position of the mouse to get the position of the element let left = e.clientX - disX; let top = e.clientY - disY; oDiv.style.left = left + 'px'; oDiv.style.top = top + 'px'; }; document.onmouseup = () => { document.onmousemove = null; document.onmouseup = null; } } } } } 3. Usage: <div class="card" v-drag id="card"> <img src="../assets/logo.png" > </div> 4. Style part (position must be set to absolute): .card { position: absolute; float: left; width: 200px; height: 200px; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: The One-Hand Rule of WEB2.0
>>: Use and optimization of MySQL COUNT function
Table of contents Preface Motivation for Fragment...
Docker has been very popular in the past two year...
This article uses an example to describe how MySQ...
When newbies develop div+css, they need to name t...
What is em? em refers to the font height, and the ...
Use JS timer to make an element to make a method ...
The error is as follows: Uncaught TypeError: Cann...
1.1 Introduction to iptables firewall Netfilter/I...
This article example shares the specific code of ...
Table of contents Million-level data processing s...
In the official MySQL dump tool, how can I restor...
This article describes the MySQL slow query opera...
1. Cause: The effect after the subbox is set to f...
1. Install tools and libraries # PCRE is a Perl l...
This article mainly records the problems and solu...