Creating resizable rows of DIVs using jQuery

I'm currently developing a scheduling widget concept. The main idea is to create a row of DIVs for each day of the week. Every row consists of a set number of time periods represented by DIVs. My goal is to enable the resizing of each DIV by dragging a handle on the left side. The first DIV on the left cannot be resized, but its size adjusts based on the resizing of the adjacent DIV. This pattern continues along the row, meaning the left-side DIV automatically resizes when the right-side DIV is resized. To achieve this, I am utilizing the Resizable widget in jQuery UI for the basic resizing functionality.

If you'd like to see an example, check out my fiddle at: https://jsfiddle.net/profnimrod/rpzyv0nd/4/

However, I've encountered two issues. Firstly, the draggable handle on the left side of each DIV (excluding the first one) isn't behaving as expected. Secondly, the Fontawesome icon within each DIV (except the first one) that I intend to use as the resize handle is not displaying properly.

Do you have any suggestions on how I could address these problems?

It's worth noting that there is a canvas element positioned behind the row-containing DIV. My plan is to incorporate graphical elements behind the rows in the future, making the row DIVs transparent.

The code snippet I'm working with can be found in the Fiddle link provided:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8>
<meta name="viewport" content="width=device-width, initial-scale=1">
... (omitted for brevity)
</script></body></html>

Answer №1

Check out this Fiddle example: https://jsfiddle.net/Twisty/0r8v47yL/29/

JavaScript

$(function() {
  $(".re-size").resizable({
    grid: 50,
    handles: "w",
    maxHeight: 50,
    minHeight: 50,
    containment: "#container",
    resize: function(e, ui) {
      ui.position.top = 0;
      ui.position.left = 0;
      ui.size.height = 50;
    }
  });
});

I've added classes to the DIV elements for easier assignment. When resizing on w, both left and width of the element are adjusted. For instance:

<div id="resizable2" class="ui-state-active re-size item">
  <div class="ui-resizable-handle ui-resizable-w">
    <span class="fas fa-cogs fa-fw"></span>
  </div>
</div>

If set with CSS at 150px width and 50px height, dragging leftward would change left to 45px and reset width to 105px. Although user-friendly from a UI standpoint, it may not be what you need for your project.

An issue unaddressed is making widening more complicated. By monitoring mouse movements in relation to the left edge, adjustments can better respond to user actions.

For a comprehensive example, view: https://jsfiddle.net/Twisty/0r8v47yL/61/

HTML

<div class="scheduleWrapper">
  <div id="canvasOverlay" style="position:absolute; width:600px !important; display:block; z-index:9999">
    <div id="container" class="ui-widget-content">
      <div id="resizable1" class="ui-state-active no-re-size item">
      </div>
      <div id="resizable2" class="ui-state-active re-size item">
        <div class="ui-resizable-handle ui-resizable-w">
          <span class="fas fa-cogs fa-fw"></span>
        </div>
      </div>
      <div id="resizable3" class="ui-state-active re-size item">
        <div class="ui-resizable-handle ui-resizable-w">
          <span class="fas fa-cogs fa-fw"></span>
        </div>
      </div>
      <div id="resizable4" class="ui-state-active re-size item">
        <div class="ui-resizable-handle ui-resizable-w">
          <span class="fas fa-cogs fa-fw"></span>
        </div>
      </div>
    </div>
  </div>
  <canvas style="width: 600px; height: 300px;"></canvas>
</div>

JavaScript

$(function() {
  $(".re-size").resizable({
    handles: "w",
    containment: "#container",
    resize: function(e, ui) {
      //console.log(e);
      var x = e.originalEvent.originalEvent.movementX;
      ui.position.top = 0;
      ui.position.left = 0;
      ui.size.height = 50;
      if (x < 0) {
        console.log(ui.size.width + Math.abs(x));
        ui.element.width(ui.size.width + 50);
      } else {
        ui.size.width = ui.size.width - 50;
      }
    }
  });
});

This information should assist you in implementing the desired functionality.

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

Setting default property values in a React component using Typescript

   Is there a way to define default property values in React components when using Typescript? I came across a post on SE suggesting the use of a static class variable called defaultProps with key-value pairs for properties. However, this method didn&a ...

Learn how to use JQuery to read and print JSON data using the $.getJSON

I am diving into a new territory, so please bear with me. As someone who has used json and serialize extensively in PHP, I am now exploring JQuery. My aim is to pass data across domains, and using a json array seems like the best approach. However, I am un ...

Validation of Numbers and Characters in DevExpress ASP.NET TextBox

When I try to use masking on the textbox for credit card format, I am having trouble entering a hyphen. It seems that the validation does not accept dashes as I only checked for numbers. Any help would be appreciated. Thank you. <script> functio ...

The meaning gets blurred when using 'this' in a prototype method

Alright, so I am working on a node application that utilizes express. In this particular application, there's an express route set up like this: var MyObject = require('./myObject') , myObject = new MyObject(); app.post('/api/w ...

If the element contains a specific class, then remove that class and apply a new

Encountering an issue here. I have 4 HTML elements structured like this: <!-- Light Color Scheme - Header False and Show Faces True --> <div class="fb-like-box h-f_dsf-t visible" data-href="http://www.facebook.com/pages/Alpine-Adaptiv ...

Refreshingly modernizing SVG in Angular

I've been facing a challenge in my Angular application where I am trying to dynamically add paths to an SVG element within an HTML file. The issue is that even though the paths are getting added to the DOM, they are not showing up in the browser when ...

Is there a way to display an image in a React Native app using data from a JSON file?

I am currently working with JSON content that includes the path of an image. I need to display this image in my React Native application. What is the best way to render this image? {"aImages":[{"obra_path":"http:\/\/uploa ...

Customizing the appearance of charts in AngularJS using the Chart.js

I just started experimenting with AngularJS and recently created a horizontal bar chart using Chart.js and HTML. My next step is to make the chart dynamically appear on the page with the help of AngularJS. Can someone please provide some guidance on how I ...

Invoking a JavaScript function within an ASP Repeater

I am looking to incorporate a JavaScript function into an ASPX page within Visual Studios 2012. This function is designed to retrieve 7 values from a database multiple times and dynamically adjust the CSS based on these values. Additionally, it targets a s ...

Locate a specific option that matches the value of the selected data-status and set it as "selected" using jQuery

Currently, I am facing an issue where I need to load 2 separate ajax responses into a select dropdown. The select dropdown will have a data-status attribute, and my goal is to loop through the options to find the one that matches the value of the select da ...

Is jest the ideal tool for testing an Angular Library?

I am currently testing an Angular 9 library using Jest. I have added the necessary dependencies for Jest and Typescript in my local library's package.json as shown below: "devDependencies": { "@types/jest": "^25.1.3", "jest": "^25.1.0", ...

Ensure that the HTML link is valid and authenticated using SESSIONS

When creating a website, one of the initial tasks I like to tackle is adding links at the bottom of the page for checking valid HTML and CSS: HTML5  •   CSS <div> <a href="http://validator.w3.org/check?uri=referer" ...

Ways to integrate mouse out functionalities using an if condition

I'm currently working on a menu using Javascript where clicking on one option will dim the other options and reveal a sub-menu. I'm looking to include an if statement in the function so that when a user mouses out of both the sub-menu and the cli ...

What is the method for invoking a function with arguments within an HTML `<p>` element?

I am looking to display like and dislike percentages on cards. <v-card v-if="software[2] == searched || searched == ''" class="software-card" > <h3>{{ software[2] }}</h3> ...

I am having trouble with the Bootstrap 5 column not functioning properly within my design

Currently working on a project with Bootstrap, where I am trying to create a footer that looks like the one in the image below: https://i.stack.imgur.com/XIbDk.png Below is the HTML code snippet for my footer: <footer class="footer"> <div class ...

"Transferring data between pages using jQuery, PHP, MySQL, and HTML

Is it possible to retrieve the value assigned to <p class="myclass"></p> using a PHP script after setting it with jQuery's $('.myclass').text('txtvalue');? For example, I want to access this value without resorting to j ...

Implementing Click-Activated Scroll-to-Div Feature in React

I need to implement a scroll-to-div feature in my React App. However, the current structure of my app is preventing me from passing refs as props correctly, making it challenging to utilize ref.current.scrollIntoView(). The layout of my code looks like th ...

Is there a method available for us to successfully deliver an email to the user who has been registered?

I am currently working on the registration page for my React app. One of the requirements is to send a confirmation email to the user's email address once they have registered. The user's account will only be confirmed once they click on the veri ...

Is it possible to compare two charts in Chart.js in a way that avoids the issue of small values appearing as large as big values?

I am currently working on a production tracking page that features multiple charts. I want to avoid inconsistencies in tracking at first glance. Is there a way to achieve this using chart.js? If not, what would be the best approach to address this issue? ...

Discovering the specific value from a fixture file in Cypress

When I receive a JSON Response, how can I extract the "id" value based on a Username search? For instance, how can I retrieve the response with an "id" value of 1 when searching for the name "Leanne Graham"? It is important to note that the response valu ...