Dragging the draggable div containing an image causes a delay in the drag and drop process

A request from the client is to make a whole div draggable, which contains text and an image. To achieve this, I transformed the div into an <li> tag and utilized Mootools draggable features for functionality. However, a problem arises when the client attempts to drag the image in Internet Explorer. The browser interprets this action as dragging the image itself and neglects the drag and drop events for the parent li element.

Is there any solution to prevent the image from being draggable or to trigger the parent's onmousedown event instead?

Below is a snippet of the HTML code:

<ul class="asset_list">
  <li id="1"><img src="test1.jpg" />Blah blah blah</li>
  <li id="2"><img src="test2.jpg" />Blah blah blah</li>
  <li id="3"><img src="test3.jpg" />Blah blah blah</li>
</ul>

And here is a portion of the JS code used for drag and drop functionality:

// Set up drap and drop
$$( 'ul.asset_list li' ).each( function( item ){
 item.removeEvents();
 item.addEvent('mousedown', function(e) {
  e = new Event(e).stop();

  // Create our clone of the asset for dragging
  var clone = this.clone( true, true );
  clone.removeEvents();
  clone.addClass( "dragging" );
  clone.setStyles(this.getCoordinates());

  var drag = clone.makeDraggable({
    droppables: [TrailStream.playlist],
    precalculate: true,
    revert: true,
   }
  });

  drag.start(e);
 });
});

Answer №1

After 5 years, I stumbled upon the same issue and discovered the perfect solution that worked for me:

'dragleave' event triggers on parent element when moving over children elements

In your scenario:

.asset_list * {
    pointer-events: none;
}

Simple yet highly effective :)

Answer №2

To work through this issue, I managed to solve it by transforming the images into spans with identical styles in terms of width, height, border, etc. I then set the background-image using an inline style. Consequently, Internet Explorer now perceives it as a standard HTML element instead of an "image," resolving the dragging problem. While not entirely optimized for accessibility, it is still a better solution compared to dragging and dropping!

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

Navigate to specific sections

I'm currently developing a website and working on creating a menu that allows users to smoothly scroll to anchors within the same page as well as anchors on different pages. Successfully implemented the scrolling functionality for same-page anchors u ...

Comparing Fetch and Axios: Which is Better?

Currently delving into the realms of axios and the fetch API, I am experimenting with sending requests using both methods. Here is an example of a POST request using the fetch API: let response = await fetch('https://online.yoco.com/v1/charges/&ap ...

The sorting feature in Angular 4 appears to be dysfunctional

I encountered an error message that reads: "The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type." After reviewing the MDN explanation, I am still struggling to identify where the problem lies. ...

Is there a way to assign a specific color to individual users in a chat?

I have successfully implemented a chat feature using Pusher, but now I want to customize the appearance by changing the color of the username for the logged-in user when they are active in the conversation. Currently, both my username and another user&apos ...

The parseJSON function is not compatible with AJAX requests

I am attempting to use ajax and retrieve JSON data in WordPress. Here is my Ajax code: $.ajax({ type: "POST", dataType : 'html', url: "/wp-content/themes/myproject/ajax/otros_alojamientos.php", da ...

Cheerio in node.js encounters a problem while reading HTML files

I am brand new to JavaScript and I've hit a roadblock with Node Cheerio. Any assistance would be greatly appreciated. The code I'm currently working on can be found here: https://github.com/zafartahirov/bitstarter. Once the issue is resolved, t ...

Comparing AngularJS $interpolate with $filter

AngularJS offers different tools for manipulating data displayed to users. While $filter is commonly used for formatting data, $interpolate enables real-time updates within a text string. Do $interpolate and $filter have any connection? How do they differ ...

Control the switch for CSS selectors

Consider the following scenario where CSS rules are defined: <style> table {background:red;} div {background:green;} </style> In addition, there is HTML code that calls a JavaScript function: <table onclick="tu ...

The jQuery .on("change") function keeps triggering repeatedly, but I'd like it to only execute once

I'm currently working on a feature that involves detecting changes to input text fields. Every time the user makes a change in an input field, I need to capture the new value and validate it. However, I've noticed that the code I have implemented ...

Building an instance using an object and an array with Vue.js 2.0

I am working with an array and an object created in Vue.js, and my goal is to combine them into a single 'selection' array following this format: selection[ {food: Chicken, quantity: 3}, {food: Rice, quantity: 2}, {food: Pasta, quantity: 1} ]; ...

Using jQuery to count children and show the outcome when hovering

I have implemented an alphabetical search functionality for products. When a letter is clicked, all products starting with that letter are displayed. However, I want to display the selected letter at the top and hide the rest of the letters. Should I use ...

Tips for distinguishing the beginning and ending points of wrapped text in the Firefox browser

Within my work, I am utilizing a contentEditable span where I aim to position an element with position: absolute on the same line as the cursor. However, issues arise when text wrapping occurs - causing abnormal behavior at the start and end of wrapped lin ...

The error message states: "Dygraph is not defined."

Currently, I am utilizing express.js in my application to render dygraph charts on the client side. You can take a look at my index.jade file here. Upon visiting my browser, an error pops up in the console: Uncaught ReferenceError: Dygraph is not defined. ...

Assess html code for Strings that include <% %> tags along with embedded scripts

Having a small issue with my code where I am receiving an HTML response from a web service as a java String. I need to display this String as HTML on my webpage, but the problem is that there are some script tags in the form of <% ... %> which are sh ...

Stream data's modification to numerous controllers post ajax loading

One issue I encountered in my Angular app is related to the asynchronous loading of data from a server. Some controllers depend on this data, which is retrieved through an AJAX request. The problem arises because controllers end up pointing to an empty arr ...

Tips on how to store the values of dynamically generated textboxes into a variable

Trying to insert dynamic values from multiple rows of textboxes into a variable, then send it through ajax json to the server side. This is the code for generating multiple dynamic values. $('#btnASize').click(function() { var sizerangeMin = " ...

What possible reasons could cause an API request to result in an empty array being returned?

I recently encountered an issue when calling this API using npm request. The response I receive is an empty array, despite having loaded request, defined the content value at the top of the page (not displayed here), and modified the API key. Surprisingly, ...

Using Bitly API in JavaScript to launch a popup window

I have implemented a script that dynamically generates short links for my Tweet buttons. It is working perfectly fine, but I am encountering an issue with opening the link either in a new tab or a popup window. I've tried adjusting the window.locatio ...

Is there a way to generate random numbers that will create a chart with a general upward trend?

Are you looking for a solution to generate random numbers for charts that trend upwards and to the right? I am currently utilizing a JavaScript charting engine, so I will require numbers in JSON format eventually. However, I am open to alternative methods ...

Handling redirection on a single-page website without javascript functionality turned on

Currently, I am in the process of creating a single-page website using html, css, javascript, and php. My aim is to use jQuery for navigating through the website - allowing the content to fade out when a user clicks on a link in the navigation menu and hav ...