Vue implements image drag and drop function

Vue implements image drag and drop function

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:
  • Vue integrates a rich text editor that supports image zooming and dragging
  • Vue implements image preview effect example (zoom in, zoom out, drag)
  • Vue implements drag and drop or click to upload pictures
  • Vue implements the problem of image scaling
  • Use vue components to realize the drag and zoom function of pictures

<<:  The One-Hand Rule of WEB2.0

>>:  Use and optimization of MySQL COUNT function

Recommend

Detailed explanation of MySQL backup and recovery practice of mysqlbackup

1. Introduction to mysqlbackup mysqlbackup is the...

Summary of MySQL Architecture Knowledge Points

1. Databases and database instances In the study ...

How to use port 80 in Tomcat under Linux system

Application Scenario In many cases, we install so...

Detailed explanation of how to use grep to obtain MySQL error log information

To facilitate the maintenance of MySQL, a script ...

MySQL tutorial thoroughly understands stored procedures

Table of contents 1. Concepts related to stored p...

Detailed tutorial on installing mysql 8.0.20 on CentOS7.8

1. Install MySQL software Download and install My...

Vue.js implements image switching function

This article shares the specific code of Vue.js t...

Docker-compose creates a bridge, adds a subnet, and deletes a network card

1. Create a docker network card [root@i ~]# brctl...

Linux automatic login example explanation

There are many scripts on the Internet that use e...

The difference between char, varchar and text field types in MySQL

In MySQL, fields of char, varchar, and text types...

...

CSS3 achieves cool 3D rotation perspective effect

CSS3 achieves cool 3D rotation perspective 3D ani...

Detailed explanation of MySql data type tutorial examples

Table of contents 1. Brief Overview 2. Detailed e...

How to monitor Tomcat using LambdaProbe

Introduction: Lambda Probe (formerly known as Tom...