unusual behavior when using the CSS property transform: rotate

i'm attempting to enable this element to be both draggable and rotatable.

However, when I apply transform:rotate(0deg);, I am able to drag it anywhere within the parent container. But when I set it to 90deg, there are certain areas that become undraggable and it also extends outside of the parent container.

<div id="container">
<div id="myitem"><p>my rotate/drag</p></div>

CSS:

#container{   
width:500px;
height:500px;
background:red;
}

#myitem{
width:115px;
height 50px;
background:black;
transform-origin:top left;
transform: rotate(90deg);
 -ms-transform-origin:top left;
-ms-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-webkit-transform-origin:top left;
}

see the example here click here for a sample of the issue

I have found a solution to the problem!

If you capture $(foo).offset().left when setting the css scale, the value does not match the actual position when using transform-origin: top left;

To solve this, replace

$(foo).offset().left with parseInt($(foo).css('left').replace('px',))
but make sure to set
position to absolute after running: foo{ top: 0; left: 0; position: absolute; }

:)

The issue arises when detecting transform-origin and the discrepancy in positions when applying a scale(). Can it be calculated by %?

Answer №1

I've been exploring your question, and it seems like what you need is a draggable and rotatable element within a container...

I took a look at your fiddle and made some modifications to help achieve this: http://jsfiddle.net/28WG3/19/

I also made some adjustments to the html code:-

<div id="container">
    <div id="main"><div id="myitem"><p>my rotate/drag</p></div>
</div>
</div>

I hope this solution meets your needs...

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

"Implementing a loading spinner on the submit button to ensure single submission and prevent

In my code, the master page includes frames for navigation purposes. On clicking the submit button on any screen, I want to disable the page to prevent further user interference. To achieve this, a div is used in the master page and the following code is a ...

Discover the outcome of clicking on an object (mock tests)

I am just starting out with React and I'm unsure about when to use mocking. For instance, within the 'ListItem' component, there is a 'click me' button that reveals a dropdown for 'cameras'. Should I focus on testing what ...

Linking jQuery UI tabs to tabs on a different pageWould you like assistance

I am facing a challenge that I need help with. For a school project, I have to create 8 pages of HTML, each with a template and a menu. The menu consists of tabs that are supposed to link to separate pages when clicked. However, the issue is that when I cl ...

What is preventing me from accessing a function that is declared using function declaration while using a debugger?

When pausing at the debugger statement, an attempt to call foo results in a ReferenceError. It appears that the function is not defined within the script's context or scope, similar to how a local variable like x is. The script example.js is as follo ...

Encountering an error with Gatsby while running the development environment due to issues with antd and less configuration (NPM

Encountering issues with the development server in local after installing antd, less, less-loader, gatsby-plugin-less, and gatsby-plugin-antd Versions: "gatsby-plugin-less": "^6.20.0", "less": "^2.7.1", "less- ...

Positioning Avatar component at the center of Card component

Hello there, I am currently trying to center my <Avatar> elements using Material UI with React within the <Card> components. The layout appears very crowded right now. What would be the most effective method to achieve this? I attempted setti ...

Controlling the Output in Typescript without Restricting the Input

I am interested in passing a function as a parameter, allowing the function to have any number of parameters but restricting the return type to boolean. For example, a function Car(driver: Function) could be defined where driver can be ()=>boolean or ( ...

Unexpected behavior encountered with JQueryUI modal functionality

Today marks my first experience with JqueryUI. I am attempting to display a conditional modal to notify the user. Within my ajax call, I have this code snippet: .done(function (result) { $('#reportData').append(result); ...

Background image color not displaying correctly

I've been attempting to overlay a transparent color on top of a background image. While the background image is displaying correctly, I'm having trouble getting the color to show up. I noticed that this question has been asked before. I tried im ...

Update the URL path with the selected tab item displayed

Is there a way to show the selected tab item in the URL path? I came across this example using Material UI: import * as React from 'react'; import Tabs from '@mui/material/Tabs'; import Tab from '@mui/material/Tab'; import Typ ...

Is your Jquery code behaving sporadically, functioning for a moment and then ceasing to

After successfully implementing a slide mechanism on a page, it suddenly stopped functioning properly without any apparent changes being made. Here is the code snippet: $(document).ready(function () { var hash = window.location.hash.substr(1); var ...

JavaScript global variables are experiencing issues with proper updates

I am facing an issue where I need lines to be stored in a global array. However, when I compare the values inside the function with those outside the function using console.log, I notice that the inside one works fine but the outside one remains empty. C ...

Choosing HTML Elements for Audio Playback in HTML5: A Guide to Selecting Elements Without Using Div IDs

When creating an HTML5 player, I am transitioning "from using divs with id's" to "simple HTML elements". Former Scenario (functional) <audio src="track1.mp3" id="audio"></audio> <controls> <play id="play" style="display:none ...

Using Ajax and jQuery to Retrieve the Value of a Single Tag Instead of an Entire Page

Let's say I have a webpage named page.html: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Page</title> </head> <body> <h1>Hello World!!</h1> </body> </html> Now ...

Sending a JS function to a PHP script

I've been incorporating the Soundcloud API into my project and successfully implemented their record button on my website. Once the upload is completed, the code generates the URL of the newly created soundcloud file. My goal now is to pass that URL ...

Exploring deep within JSON data using jQuery or Javascript

I have a substantial JSON file with nested data that I utilize to populate a treeview. My goal is to search through this treeview's data using text input and retrieve all matching nodes along with their parent nodes to maintain the structure of the tr ...

Add a prefix to every hyperlink in an HTML document

I'm looking to transfer an HTML template to a Google site using embedded code. The template includes a table with over 500 links that need to be prepended. Is there a method to achieve this without relying on JavaScript? <table class="wikitabl ...

Shifting text higher to the <h1> tag using CSS

I'm currently attempting to move the paragraph header closer to my h1 title. I'm struggling with incorporating the position function and have tried using padding without success. On the image, I am aiming to position the text "Where every connec ...

Obtaining all tweets from a specified username using PHP

After collecting 3200 tweets using API v1.1, I attempted to retrieve all tweets by running a cron job as a background process. However, this method did not increase the total number of tweets. I am seeking suggestions on how to obtain all tweets either th ...

pair each instance of a string

Currently, I am developing a todo list application that allows users to add to-do list items and search for specific tasks. My focus at the moment is on refining the search function. Presently, whenever a user searches for a name, only the first task ass ...