Combining CSS3 transform scale with jQuery UI resizable for enhanced functionality

I am currently working on factoring in the impact of scaling an element while utilizing jquery ui resizable.

Although there have been some discussions regarding css3 transform issues with resizing/dragging, I have not come across a solution that works effectively.

For now, I am putting the rotation problem on hold and focusing on getting it to function with scale.

I was able to make adjustments to the draggable feature, but I am encountering difficulties with the resizable functionality.

HTML

 <div id= 'div1'> 
resize the div and take note of how the mouse cursor's
distance from the resize handle increases over time
<div>

  CSS
 #div1{
  margin:100px;
 width:100px;
 height:100px;
 border:1px solid black;
 font-size:12pt;
 overflow:hidden;
 -webkit-transform:scale(2);
 }​​

  JS
 $('#div1').resizable();

http://jsfiddle.net/asaf/JBE2r/1/

Answer №1

To achieve this goal, one effective method is to adjust the dx and dy variables by dividing them by the transform scale attribute within the _mouseDrag event. (In my scenario, the x and y transform values always remain consistent) I am initializing the 'scaleFactor' parameter during the mousestart event.

    _mouseDrag: function(event) {
   console.log(this.size.width);
 var xDiff = event.pageX / this.originalMousePosition.left;
 //console.log(xDiff);

    //Optimizing performance, avoiding regex
    var el = this.helper, o = this.options, props = {},
        self = this, smp = this.originalMousePosition, a = this.axis;

    var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0; 
    var trigger = this._change[a];
    if (!trigger) return false;

    //Adjusting dx and dy below by the transform scale factor:

    dy = dy / self.scaleFactor;
    dx = dx / self.scaleFactor;

Answer №2

I provided a solution to the issue at hand and shared the specifics in this post:

It's unnecessary to modify the source code of jquery-ui. All that is required is a callback for the resize event of the resizable element that compensates for the scale factor as shown in the CodeToads response.

function resizeFix(event, ui) {
    var changeWidth = ui.size.width - ui.originalSize.width; // calculate width change
    var newWidth = ui.originalSize.width + changeWidth / zoomScale; // adjust new width based on zoomScale

    var changeHeight = ui.size.height - ui.originalSize.height; // calculate height change
    var newHeight = ui.originalSize.height + changeHeight / zoomScale; // adjust new height based on zoomScale

    ui.size.width = newWidth;
    ui.size.height = newHeight;
}

$(this).resizable({
    minWidth: -(contentElem.width()) * 10,  // these values should be large and negative 
    minHeight: -(contentElem.height()) * 10, // to allow resizing while scaled
    resize: resizeFix
});

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

Changing ch to Px in CSS

Important Notes: I have exhaustively explored all the questions and answers related to this particular topic. The question I have is very straightforward: How many pixels are equivalent to 1 character? Here's a sample of my code - code Related Sear ...

The issue of Jquery .click event handler failing to work for class selector specifically in CHROME

Is there a way to achieve the same opacity effect on click as on mouseover? I've tried various selectors without success. Any help on this issue would be greatly appreciated. Thank you in advance! .container { position: absolute; background:url(&a ...

Aligning a div in relation to the background image

I am seeking guidance on how to center a Div Box and make it responsive relative to the background image. The div box should be contained within the white box, similar to the example shown here: body{ font-family: 'Roboto Mono', monospace; ...

What is the best way to use jQuery ajax to send various row identifiers when updating table data on another PHP page by selecting checkboxes?

When I select both of the green checkboxes, only the most recent table id is sent. The code below includes both the checkbox markup and jQuery function. Checkbox: <div class='md-checkbox has-success'> <input type='checkbox&apo ...

Give instructions on how to sequence multiple ajax requests in a specific order

I have a collection of div elements in jQuery. Each div requires two separate ajax calls, where the result of the first call is used in the second call. These ajax requests each take about one second to complete. If I loop through the divs like this: $di ...

What benefits does sending data in JSON offer when using JQuery Ajax?

I created a form that sends the input values using ajax: var data = { id : $("#tabs").tabs('option', 'selected'), title : $('#name').val(), csrf_token : $("input[name=csrf_token]").val() }; Wh ...

What is the best way to eliminate the space between two columns of a row in Bootstrap 5 grid system?

In my quest to achieve the grid layout illustrated in the image below https://i.sstatic.net/4hsjw.jpg .col_1{ background-color: bisque !important; height: 500px; } .col_2 { width: 300px; height: 287px; background-position: cent ...

Can one open a unique custom pop-up before the window is about to close?

Seeking a way to create a pop-up confirmation dialog for users when they try to log out or stay on the page while logged in. I attempted using the code below, but haven't been able to find the correct solution: window.onbeforeunload = function (e) { ...

Is there a way to configure the positioning of Bootstrap carousel thumbnails to be above and beside?

My goal is to customize a bootstrap 5 thumbnails carousel by placing the thumbnails either on the top or the left side of the slides section. The default setting is at the bottom, but I need these two variations. The base model works perfectly, but I' ...

What is the best way to halt a CSS transition using JavaScript when dealing with an image?

I am facing an issue while attempting to create a basic CSS transition using JavaScript. The goal is for the start button to trigger the movement of an element, based on the duration of the keyframe animation. Then, clicking the end button should make the ...

The troubleshooting issue with jQuery animate Scrolltop malfunctioning

My goal is to use jQuery to scroll the page to a specific div when a button is clicked. Despite not seeing any errors in the JavaScript console, the page does not actually scroll to the desired location. I have tried placing the jQuery js file before and a ...

Retrieving information from a table row and using it as a parameter in the URL for an AJAX request

New to implementing ajax, JQuery, and Json in my strut2 web application. I have a table on one web page with records displayed, and the last column contains an image as shown below. Currently using an anchor tag with an image for the last column with an ac ...

Generate unique identifiers to rotate images dynamically on the webpage

My goal is to rotate every image on a page, and while this works with a single image, it only rotates the first one since each ID needs to be unique. I need to find a way to dynamically increment the IDs as they are encountered on the page. Below is what I ...

Utilizing d3.js to filter a dataset based on dropdown selection

I am working with a data set that contains country names as key attributes. When I select a country from a dropdown menu, I want to subset the dataset to display only values related to the selected country. However, my current code is only outputting [obje ...

Creating an expand and collapse animation in a `flex` accordion can be achieved even when the container size is fixed using

Good day, I am in need of a fixed-height HTML/CSS/JS accordion. The requirement is for the accordion container's height to be fixed (100% body height) and for any panel content overflow, the scrollbar should appear inside the panel's content div ...

When using jquery.hide() and show(), the content within the div disappears momentarily before reappearing

Hello! I am experiencing an issue where the content of my div disappears after using a jQuery hide() and show() function. It seems to be gone. <li class="gg3"><a class="link" href="#" data-rel="content3">Link1</a></li> <div clas ...

Get back a variety of substitutions

I have a variety of different text strings that I need to swap out on the client side. For example, let's say I need to replace "Red Apple" with "Orange Orange" and "Sad Cat" with "Happy Dog". I've been working on enhancing this particular ques ...

Uploading Images Dynamically with AJAX

Can someone assist me with a multiple upload form that utilizes AJAX to upload and display an image without the need for a submit button? My issue arises when dealing with repeating forms within table rows, causing only the first form to function properly. ...

Empty space under the banner in Wordpress theme Avada

I can't seem to locate the CSS class for a blank space that appears below the header on one of my pages. This space is situated between the header and "SERVICIOS 24 HORAS". Any ideas on how I can remove this mysterious gap? My website is built wit ...

What is the best way to place a JavaScript or jQuery variable within an HTML tag?

Suppose we have a variable called var sticky_element = ".menu"; and then there's this line of code: jQuery(sticky_element).wrapInner('<div class="menu-inner"></div>'); How do we replace the menu in class="menu-inner" with the ...