Is the accuracy of the alsoResize functionality in Jquery UI Resizable questionable?

After removing the 'alsoResize' option, I found that the behavior remains unchanged.

Upon resizing the main element, I noticed that the black border of the bottom element, 'marquee,' often shifts out of alignment with the dashed white border of the top element.

$(".layer").resizable({
    //alsoResize: '.marquee',
    resize: function(event, ui) {
        $('.marquee').css({
            width : ui.size.width + "px",
            height : ui.size.height + "px",
            left : ui.position.left + "px",
            top : ui.position.top + "px",
        });
    },
    handles: 'all',
    aspectRatio: true,
});

http://jsfiddle.net/digitaloutback/uGr3w/3/

When inspecting with Firebug on a local demo, I observed that when they go out of line, the inline styles for left, top, width, and height are different.

I'm considering whether a solution would involve sending position and size statistics to a function that will provide precise measurements to both elements. Are there any simpler alternatives? Thank you.

UPDATE:

I have developed a clean workaround... by passing the dimensions calculated by resizable to a function that sets the top layer to these same dimensions.

I believe there may be a more efficient way to achieve this, so please feel free to suggest an optimized version...

http://jsfiddle.net/digitaloutback/VDfpY/5/

Answer №1

There appears to be a discrepancy in the reported size and position from the ui parameter during the resize event, compared to the actual sizes and positions. The issue may stem from a delay between the creation of the ui parameter and the firing of the event.

To address this, I conducted an experiment where I used the real-time position and size data at the moment the event executed:

        $('.marquee').css({
            'left' : $(this).position().left,
            'top' : $(this).position().top,
            'width' : $(this).width(),
            'height' : $(this).height()
        });

This adjustment resulted in a much more precise alignment with the actual dimensions. http://jsfiddle.net/VDfpY/1/

Answer №2

Have you considered letting CSS manage the sizes instead of JavaScript? Check out this example on jsFiddle

--updated with code snippet--

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

    $(".layer").resizable({
        handles: 'all',
        aspectRatio: true,
    });

});
</script>
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/themes/redmond/jquery-ui.css" rel="stylesheet" />
<style type="text/css">
#canvas { 
    width: 500px; 
    height: 500px; 
    position: relative; 
    overflow: hidden; 
    background: #999}

.marquee {
    border: 1px dashed #fff;
    position: absolute;
    left: -1px; top: -1px;
    width: 100%; height: 100%;
    display: block;
    z-index: 2500;    
}

.layer {
    border: 1px solid black;
    position: absolute;
    left: 150px; top: 150px;
    width: 250px; height: 226px;
    display: block;
    z-index: 2501;
}
</style>
<body>
<div id="canvas">
    <a class="layer" href="#"><span class="marquee"></span></a>
</div>
</body>

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

Identify the active slide and execute a corresponding function in ANgularJS

I am currently using a slider jQuery plugin to rotate images on a timer. The plugin is minified so I am unable to read the source code. My goal is to have Angular automatically update a model every time the slide changes, which will then update content o ...

Is your Bootstrap button displaying a blue border?

Recently, I incorporated buttons into my website using a bootstrap template. However, after customizing the button colors, I discovered an annoying blue outline appearing around each button. Despite numerous attempts, I have been unsuccessful in eliminatin ...

NodeJS Fork - React each instance a new line is detected from the child process

I am currently working on creating a NodeJS function (on Windows7) that listens to a subprocess and handles each newline sent through the subprocess in Node. The following example demonstrates this: var express = require('express'); var app = ex ...

When using jQuery to parse JSON, I am unable to make changes to an array

inventory = new Array(); $.getJSON('items.php', function(data){ $.each(data , function(i,jsonData) { inventory[1] = "item"; }); }); alert(inventory[1]); This code is supposed to display the items in the inventory, but it's ...

Centered text with custom images in an HTML list

I'm experimenting with customizing lists and currently using a custom list-style-image. I'd like to know how to center the text and image so they are always aligned, even in the case of multi-line text. I've included a picture for reference. ...

The import error occurred because the module 'styled-components' does not export 'createGlobalStyle'

I am encountering an issue while attempting to import createGlobalStyle from styled-components. Despite having installed the styled-components npm package with version @3.4.10, it doesn't seem to work as expected. const GlobalStyle = createGlobalStyl ...

Obtaining JSON data in a separate JavaScript file using PHP

I have an HTML file with the following content: // target.html <html xmlns="http://www.w3.org/1999/xhtml"> ... <script src="../../Common/js/jquery-ui-1.10.3.js"></script> <script src="../../Common/js/select.js" type="text/javascript"& ...

Examining if elements in a mapped array have common values

Currently, I am working on creating a news feed with React and moment.js. By utilizing the .map method, I am able to display items with titles and content. My goal is to determine if an item was published in the same year and month as another item. In such ...

JavaScript - Struggling with decoding a JSON object

Having some difficulty with JSON object parsing, Take a look at my code: var data = '[{"image:loc":["https://cdn.shopify.com/s/files/1/0094/2252/products/YZY-KW3027.053.jpg?v=1539344090"],"image:title":["Yeezy WMNS Tubular Boot Washed Canvas - Limes ...

Angular does not seem to support drop and drag events in fullCalendar

I am looking to enhance my fullCalendar by adding a drag and drop feature for the events. This feature will allow users to easily move events within the calendar to different days and times. Below is the HTML code I currently have: <p-fullCalendar deep ...

What methods can be used to protect (encrypt using Java code) the information in a login form before it is sent to a servlet for

One major concern I have involves sending encrypted data (encrypted before sending the request) to a servlet. I attempted to call a function that encrypts passwords as an example, but I encountered difficulty passing values from JavaScript to Java code in ...

How to align a child element in the center when the parent is not centered or taking up the full width

I am currently working on building a layout with Bootstrap 4.6, and I am facing an issue with centering the header, columns/cards, and buttons on the page width while the parent container is left-aligned and not full width. Additionally, I need help with ...

Tips for interacting with the DOM in an Angular 4 application

I am trying to call the addItems method, but I keep getting an error: Uncaught TypeError: this.addItems is not a function Currently, I am using Angular 4 along with jQuery and the fullpage.js library. page-content.component.ts import { Component, OnI ...

Exploring creative solutions for generating PDFs with Node JS

Looking for a way to generate PDF Documents in Node.JS? Is there an alternative solution for organizing templates for various types of PDF creation? I've been utilizing PDFKit for creating PDF Documents on the server side with Javascript. Unfortunate ...

ngRepeat does not completely refresh the DOM when dealing with a basic array

I have a simple array of numbers shown below using ng-repeat: n = [1,2,3,4,5,6] The problem arises when I modify this array, for example: n=[1,2,3] Instead of fully reloading the DOM, only the last 3 div elements corresponding to array 4, 5, 6 are remo ...

What is the best method for serializing data associated with the current item in a jQueryUI sortable list?

Currently working with jQueryUI 1.8.14, I am interested in creating a sortable list and saving any changes to item positions in my application database whenever a user adjusts an item's position. To achieve this, my plan is to retrieve and serialize ...

Steps for initiating an XMLHttpRequest in a XUL setting

When working in the XUL environment, I experimented with various methods using jQuery like this: $.ajax({ url:'http://www.X-site.com/api/call.php?q=test', success: function(){alert('success');}, error: f ...

Is it possible to execute NodeApp in a command-line fashion?

NodeApp's NLContext has the capability to interpret JavaScript using evaluateScript. Additionally, it also supports argv and env: Current functionalities: process: .argv, .env, .exit(), .nextTick() How can NodeApp be executed in a command-like man ...

Toggle the visibility of the route layer in Leaflet by clicking on a button using the Easy Button plugin

I am working on a Leaflet map that includes a button (utilizing the Easy Button plugin from https://github.com/CliffCloud/Leaflet.EasyButton). Upon clicking this button, a route layer is added to the map using the Leaflet Routing Machine plugin (https://gi ...

Tips on serving a static file from a location other than the public or view directories following middleware in Express JS

I am organizing my files in a specific way. Inside the folder api-docs, I have an index.html file along with some CSS and JS files. My goal is to display the API documentation only for authenticated users. Since I am using Jade for views in this proje ...