Unable to drag and drop onto every part of a div element that has undergone a CSS transformation

Having trouble implementing a Drag & Drop feature. The droppable div is styled with CSS transformations, but the draggable div doesn't drop correctly on the right part of the box.

If you'd like to take a look at the code and try it out yourself, here's a simplified version along with a jsFiddle link: https://jsfiddle.net/t5e2qvgt/8/

$("#draggable").draggable();
$("#droppable").droppable({
  drop: function(event, ui) {
    $(this)
      .addClass("ui-state-highlight")
      .find("span")
      .html("Dropped!");
  }
});
#draggable {
  width: 50px;
  height: 50px;
  padding: 0.5em;
  float: left;
  margin: 10px 10px 10px 0;
}

#droppable {
  width: 150px;
  height: 150px;
  padding: 0.5em;
  float: right;
  margin: 10px;
}

.droptarget {
  -webkit-transform-origin: 100% 100%;
  transform-origin: 100% 100%;
  -moz-transform: skew(45deg, 0);
  -ms-transform: skew(45deg, 0);
  -o-transform: skew(45deg, 0);
  -webkit-transform: skew(45deg, 0);
  transform: skew(45deg, 0);
}

.droptargeticon {
  -moz-transform: skew(-45deg, 0);
  -ms-transform: skew(-45deg, 0);
  -o-transform: skew(-45deg, 0);
  -webkit-transform: skew(-45deg, 0);
  transform: skew(-45deg, 0);
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<div id="droppable" class="droptarget ui-widget-header">
  <div class="droptargeticon">
    <p>Drop here</p>
  </div>
</div>
<div id="draggable" class="ui-widget-content">
  <p>Drag</p>
</div>

Answer №1

Seems like the content-box of the element is not being transformed correctly due to a flaw in the browser implementation. The assumption that the browser understands the new transformed context box is incorrect.

$('#droppable').outerWidth() // 189

It's clear that the width exceeds 189, as a matter of fact, 189 represents the width of the element without the skew transform

The position does change

// With transform
$('#droppable').position(); // { top: 0, left: 189 }

// Without transform
$('#droppable').position(); // { top: 0, left: 357 }

The transform only seems to alter the position to the upper left corner of the skewed element in the DOM, without changing anything else, thus it does not accurately reflect the shape of the visible element.

This issue may be a limitation within the browser and the DOM that cannot be resolved :(

Regardless of using raw JavaScript or jQuery, the outcome remains the same, indicating that the problem lies beyond jQuery.

An alternative approach could involve creating a wrapper around the droppable area and placing the skewed element inside it, although this would result in a larger square drop target.

UPDATE

I have reported this issue as a bug to Chromium, you can view the discussion. Essentially, they advised me to request standardization from the W3C so that it can be implemented across all browsers. I'm not pursuing that route, but feel free to do so on your own.

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

Issue with min-height property in IE8 (and potentially other browser versions)

Trying to design a web page with 3 sections, each occupying 100% of the window height. Managed to make it work on Chrome, Firefox, and Safari, but facing compatibility issues with IE8 and possibly other versions. Test out the page here: Here's the H ...

What is the best way to emphasize specific months and years in an Angular Material datepicker?

I have an array of days, which can be from any year. I am attempting to customize the Angular Material datepicker to highlight specific months and years in the selection views based on the array of days. .html <input [matDatepicker]="picker" ...

When using jQuery to select elements of a specific class, make sure to exclude the element that triggered the

A dynamic number of divs are generated from a data source. Each div contains an image button and another div with text. While the actual scenario is more complex, we can present a simplified version: <div id="main"> <div id="content_block_1" ...

Experiencing difficulties with a callback function while making a jQuery getJSON request via AJAX

Within my utility .js file, there is a method that fetches data using Ajax. The challenge I am facing is that this method does not have prior knowledge of the caller. After the Ajax call completes asynchronously, it needs to send an object back to the cal ...

Issue with displaying the Bootstrap paginator stylingSomething seems to be

Currently, I am working on a PHP project that involves creating a table with Bootstrap styling. To achieve this, I referred to a tutorial which guided me through the process. After linking the necessary Bootstrap CSS file using the provided code snippet, ...

Utilizing CSS to create dynamic 3D cube transformations

Exploring the realm of CSS 3D transforms to showcase cubes and cuboids featuring cross-sections has been my current venture. In this endeavor, I'm aiming at compatibility with Chrome, Firefox, and MSIE 11. It has come to my attention that in order to ...

Display <span> next to <select>

Currently, I have a <span> and a <select>. However, in the following code, the <span> is displayed above the <select>. My goal is to arrange it so that the <span> is shown first, followed by the <select>. .requiredSta ...

Navigating a local and server environment with relative paths in a web server's multiple sites

My ASP.NET website is published to a web server with multiple sites, such as www.example.com/SiteA or www.example.com/SiteB. Before publishing, I test the site locally at localhost:12345. When referencing an image path like /Images/exampleImage.gif, it wo ...

"Crafting a sleek card design using Material UI components in React JS

Exploring the world of material UI and looking to create a card with an image and footer. However, I'm facing challenges as there is no default option for adding a footer in the card. https://i.stack.imgur.com/xlxyb.png I want the image to be center ...

Tips for exchanging JavaScript variables with PHP using AJAX

Hey there, I'm new to JavaScript and I've hit a roadblock with passing variables to PHP using Ajax. <script> $date = "123"; $.ajax({ url: './record.php', type: "POST", ...

Add text to the forefront of video content while in fullscreen mode

Currently, I am facing an issue while trying to embed a video from YouTube. I am unable to draw anything (text, image, etc.) when the video is in fullscreen mode. Despite my attempts to use z-index, it has not been successful. My goal is to create a n ...

Replacing a string in a textarea using Jquery

Trying to dynamically replace a string value in a textarea while typing into a textbox using jQuery. Utilizing the keypress event for this functionality. Any ideas on what could be causing issues with this example? <input type="text" id="textbox" /> ...

The complexities of stopPropagation() causing further confusion

I have encountered an issue with my code. It currently allows a dropdown functionality for a <ul> element, but when a child <li> is clicked, it also closes other menus of the same type. To fix this, I used an if clause to check if the clicked ...

What is the best way to make HTML adjust to SVG scaling?

After applying a scale transform to an SVG, I noticed that the surrounding HTML does not adjust its size accordingly. Here is the SVG in question: <div> <svg height="300" width="300" viewbox="0 0 300 300" transform="scale(1.55)" xmlns= ...

Utilize JavaScript to parse JSON containing multiple object settings

After receiving the server's response, I am looking to extract the "result" from the JSON data provided. This is my JSON Input: { "header":{ "type":"esummary", "version":"0.3" }, "result":{ "28885854":{ "uid":"28885854", "pub ...

Show real-time server responses using jQuery while waiting for the AJAX request to complete

I have a challenge in creating a function that displays the server response while waiting for Ajax to complete. Here's the scenario: I have selected 10 checkboxes. When I click the submit button, Ajax is triggered. On the server side, there is a loo ...

Trigger Heartbeat Signal on Page Access using jQuery

I have created the following jQuery script to send a Heartbeat message back to PHP every 3 seconds, and it is functioning correctly. The purpose of this script is to track which users are currently logged in and active on the site. setInterval(function () ...

What is the best way to compare a string with a specific object key in order to retrieve the corresponding value?

I'm looking to achieve a relatively simple task, or at least I think so. My goal is to compare the pathname of a page with key-value pairs in an object. For example: if("pathname" === "key"){return value;} That's all there is to it. But I&apos ...

Working with both Javascript and jQuery code within a single HTML file

I recently created a website and on one of the pages, I added some jQuery elements like a start button and progress bar. However, when I tried to implement a JavaScript timer on the same page by adding the script into the header, the jQuery elements stoppe ...

How can I use the select2 jQuery plugin with the tags:true option to ensure that selected choices do not appear again in the dropdown menu?

Transitioning to select2 for tagging from a different plugin, I'm facing a gap that I need to address in select2's functionality. Let's consider an example. Suppose my list of choices (retrieved server-side via Ajax request) is: "Dog", "Ca ...