drag items on your smartphone with ease

Hello everyone, I am looking to make items draggable on a smartphone as well.

Here is my HTML code:

<input class="inputText mb-2 border border-primary rounded" v-model="newTodo" 
 @keypress.13='addTodo' placeholder="Write something"> 
 <button class="btn btn-info" @click="addTodo">
   <i class="far fa-paper-plane"></i>
 </button> 

 <ul class="col-12">
  <div v-for="(todo, n) in todos" draggable="true" @dragstart="dragStart(n, $event)" 
   @dragover.prevent  @dragend="dragEnd" @drop="dragFinish(n, $event)">
   <li class="mt-2 todo">
      Check out how Nando dances {{ todo.name }}
   </li> 
  </div>
 </ul>

This is my JS code:

 const app = new Vue({
   el: '#app',
    data: {
     todos: [{}],
     dragging: -1,
    },
   mounted() {
     if (localStorage.getItem('todos') && localStorage.getItem('list')) {
       try {
         this.todos = JSON.parse(localStorage.getItem('todos')); 
         this.list = JSON.parse(localStorage.getItem('list')); 
       } catch (e) {
         localStorage.removeItem('todos'); 
         localStorage.removeItem('list');
       }
     }
   },
    methods: {
     addTodo() {
       if (!this.newTodo) {
         return;
       }
       this.todos.push({
         name: this.newTodo,
         isHidden: true,
         isActive: false,
       });
       this.list.push(this.newTodo + '\n'); 
       this.newTodo = ''; 
       this.saveTodos(); 
     },
     dragStart(which, ev) {
       ev.dataTransfer.setData('Text', this.id);
       ev.dataTransfer.dropEffect = 'move';
       this.dragging = which;
     },
     dragEnd(ev) {
       this.dragging = -1;
     },
     dragFinish(to, ev) {
       this.moveItem(this.dragging, to);
       ev.target.style.marginTop = '2px';
       ev.target.style.marginBottom = '2px';
     },
     moveItem(from, to) {
       if (to === -1) {
         this.removeItemAt(from);
       } else {
         this.todos.splice(to, 0, this.todos.splice(from, 1)[0]);
       }
     },
   },
   computed: {
     isDragging() {
       return this.dragging > -1;
     },
   },
 });

It works perfectly on a PC, but when testing it on a smartphone, it doesn't seem to function correctly...

I believe that I have provided all the necessary details, but Stack Overflow is prompting me to include more text due to too much code and too little explanation. However, I find the question and code to be clear and concise!

Answer №1

Dealing with a similar issue on a recent project, I was unable to find a solution using VueJs alone. However, incorporating the vue2-touch-event plugin and leveraging the interact.js library provided me with more precise control over specific DOM elements. I would suggest trying out vue2-touch-event if you want an easy way to enhance your application without major code modifications.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing my node-statsd client script to not terminate?

When attempting to log a metric to a StatsD server using the node-statsd library, I encountered an issue where the script did not exit automatically. The code snippet in question is as follows: var StatsD = require('node-statsd').StatsD; var cli ...

Setting up Visual Studio Code for debugging HTML and JavaScript code

Struggling to troubleshoot some HTML/JavaScript using VSCode. After installing the Chrome debugger extension and configuring the launch.json as follows: { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of ex ...

Having difficulty in replicating and obtaining flash video content from a website through HTML coding

I'm having trouble downloading a flash video, as traditional download software isn't working. I attempted to directly access the video from the html script itself, following this tutorial : https://www.youtube.com/watch?v=waE3J0Jej_0 The script ...

The trio of Javascript, Ajax, and FormData are

I'm struggling with sending form values to a PHP file. Here's the code I have: <form role="form" id="upload_form" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="formlabel">Title< ...

Creating a stylish gradient text color with Material-UI's <Typography /> component

Is there a way to apply a gradient font color to a <Typography /> component? I've attempted the following: const CustomColor = withStyles({ root: { fontColor: "-webkit-linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)", }, })(T ...

Ways to dynamically link a JSON response object to an entity?

In my ng2 implementation, I have a user.service.ts file that calls a REST service and returns JSON data. The code snippet below shows how the getUser function retrieves the user information: getUser(id: number): Promise<User> { return this.http. ...

Issues with sending data through ajax using the post method persist on shared web hosting

I'm facing an issue with Ajax post data. It works fine on localhost but not on shared hosting. Here is my code: <script type="text/javascript> $(document).ready(function(){ $("#login").click(function(){ alert(& ...

Personalized configurations from the environment in the config.json file

I need to dynamically populate a setting object in my config.json file based on environment variables. The settings should vary depending on the environment. "somesetting": { "setting1": "%S1%", "setting2": "%S2%" } I am currently working on Wind ...

Is there a way to provide a dynamic value for the p:remoteCommand ajax call?

My issue involves a p:dataTable that contains p:commandLink elements. I need to initiate an ajax call with parameters when the mouseover event occurs. After some research, it became clear that commandLink cannot trigger an ajax call on mouseover directly - ...

What is the best method for obtaining the HTML content of a webpage from a different domain?

I'm in the process of creating a website where I have the requirement to retrieve the HTML content of a different site that is cross-domain. Upon researching, I came across YQL. However, I don't have much experience with YQl. Is it possible to ad ...

effective ways to extract objects from nested structures using a specific identifier

In this sample data, I am looking to filter an object based on its ID key let myData = { "nodeInfo": { "9": { "1": { "ID": "14835" ...

Creating a multi-dimensional array in JavaScript with two different sizes

I'm struggling to find the best way to create a multi-dimensional array with varying sizes dynamically. Our user interface requires a pattern where there are rows of 4 items followed by rows of 3 items. This pattern should continue until all contents ...

Exploring the meaning behind RxJS debounce principles

Referencing information found in this source: const debouncedInput = example.debounceTime(5); const subscribe = debouncedInput.subscribe(val => { console.log(`Debounced Input: ${val}`); }); When the first keyup event occurs, will the debouncedI ...

Facing issues connecting to my MongoDB database as I keep encountering the error message "Server Selection Timed Out After 3000ms" on MongoDB Compass

I am encountering an error on my terminal that says: { message: 'connect ECONNREFUSED 127.0.0.1:27017', name: 'MongooseServerSelectionError', reason: TopologyDescription { type: 'Single', setName: null, maxS ...

Please provide the date using the Foundation Datepicker tool

Beginner in JavaScript here! I am having an issue with submitting dates selected using the Foundation Datepicker from . I have searched for solutions on StackOverflow like Post form on select with JQuery Datepick, but none seem to work in my case. If a Ja ...

When using CSS float:left and overflow:visible, the text may get cropped-off at

I'm currently experimenting with creating a color gradient in javascript using numerical values within some of the divs to indicate scale. However, I've run into an issue where as the values get larger, they are cut off due to the float:left prop ...

The process of inserting data using NextJS Mysql works seamlessly when executed through phpMyAdmin, however, it encounters issues when

My SQL query works perfectly in phpmyadmin, but I'm encountering an issue when making a request from the API. The API uses the MySQL package which was installed using: npm i mysql This is the SQL code that is causing the problem: BEGIN; INSERT INTO A ...

What is the process of compiling a Vuejs single file component?

Seeking assistance with Vuejs 2 (webpack-simple template) - I am looking for a way to compile my template before rendering it. Below is the code snippet in question: App.vue <template> <div id="app"> <h1>{{ msg }}</h1> ...

Having trouble getting the toggle button JavaScript code to function properly in React JS?

I'm in need of some assistance with the comment section located below the JavaScript Code. I am trying to implement a toggle button / hamburger button, but it seems that addEventListener is not necessary for ReactJS. Can someone provide guidance on wh ...

Modify the properties of an element based on another

Situation : I am facing a challenge where I need to adjust two components based on a click event. The function linked to the onclick event handleChange includes a prop 'text'. Each time the onclick event is triggered, I must modify the value of t ...