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

I'm experiencing an issue where my JavaScript function is only being triggered

I have a simple wizard sequence that I designed. Upon selecting an option from a dropdown menu on the first page, a new page is loaded using jQuery ajax. However, when clicking back to return to the original page, my modelSelect() function, responsible for ...

What is the best way to route a localpath to a different page including parameters in Nuxt Js?

Hello, I am facing an issue where I need to pass parameters in the URL to another page in NuxtJs props: { idPending: { type: Number, required: true } }, methods: { fetchpage() { const orderId = this.idPending; this.$rou ...

One set of objects is active in retrieving data, while the other remains inactive

I'm working with an array of objects and here is what it looks like: const default_apps = [ { 'post_title': 'Excel', }, { 'post_title': 'Word', }, { 'post_title': 'SharePoi ...

Using jQuery to incorporate a variable into JSON schema markup

For my current project, I am attempting to extract the meta description and incorporate it into JSON schema markup. However, I am facing difficulty in passing the variable properly into the JSON structure. My initial approach was as follows: <script&g ...

Placement of Search Bar

After integrating a search bar into my website using code injection points, I am now attempting to relocate it below my site's tagline. The screenshot below illustrates what I am aiming for. You can visit my website at www.jobspark.ca <script typ ...

Angular debounce on checkboxes allows you to prevent multiple rapid changes from

Managing multiple checkboxes to filter a dataset can be tricky. I am looking for a way to debounce the checkbox selection so that the filter is only triggered after a certain period of time, like waiting 500ms to a second after the last checkbox has been c ...

Managing multiple Socket.io connections upon page reload

I am currently developing a real-time application and utilizing Socket.io for its functionality. At the moment, my setup involves receiving user-posted messages through the socket server, saving this data to a MySQL database via the controller, and then b ...

Creating an HTML element within a three.js globe

I have a globe created using three.js Reference: I am trying to display an HTML div at a specific latitude/longitude on the globe. Can someone guide me on how to position the div at a particular lat/long? What I've attempted: I'm currently stu ...

Implementing an API route to access a file located within the app directory in Next.js

Struggling with Nextjs has been a challenge for me. Even the most basic tasks seem to elude me. One specific issue I encountered is with an API call that should return 'Logged in' if 'Me' is entered, and display a message from mydata.tx ...

Tips for creating a sticky bootstrap column that remains in place as you scroll

I am looking to design a FAQ page similar to Twitter's FAQ. The goal is to have the left column remain fixed in its position while allowing users to scroll through the content. Here is what I have attempted so far, but it is not functioning as expect ...

Implementing a one-time watcher with user input in Vue.js

I am facing an issue with using the input tag in a Vue template. I need to change the type from 'password' to 'text'. <input type="text" v-model="form.password" /> To achieve this, I have created a watch code to convert text s ...

angular 4 observable is yielding an [object Object]

My frontend is built using Angular 4, while my backend consists of Laravel 5.5 serving as the restful API. When interacting with the backend, everything works smoothly as I am able to send curl requests and receive back the expected JSON response with 2 ke ...

``There seems to be an issue with the Express app when trying to access it

I have set up an express app that I want other devices on the same WIFI network to access without requiring internet connectivity. The main computer hosting the app is assigned with a fixed IP address: 192.168.1.60 In my server.js file, I have included t ...

File uploading using JQuery and AJAX

An error occurred: Cannot read property 'length' of undefined I'm facing an issue with 3 file fields and their upload buttons. The problem lies in the fact that the file field is being returned as undefined. Here is the JavaScript code: $ ...

The login page continues to show an error message for incorrect credentials unless the submit button is clicked

My current project involves a React component called "Signin.js". Within this component, there are login input fields as I am working on creating a login system using Node.js, Express.js, and MySQL. To achieve this, I have set up a post request that sends ...

Guide to including objects into your project without the need for babel through the use of CDN

I'm struggling with getting my Vue code to transpile properly due to some issues. I have resorted to loading Vue and other packages directly using CDN links, like this: <script src="https://cdnjs.cloudflare.com/ajax/libs/survey-vue/1.8.33/surv ...

Using CSS syntax to target a class within an element distinguished by its unique id

Consider the following code snippet: <div id="dogs" class="content">hello</div> <div id="frogs" class="content">hello</div> <div id="hogs" class="content">hello</div> <div id="logs" class="content">hello</div&g ...

"Sending the selected pass selector as a parameter to the dispatched action is causing a typing

When a selector changes its value, I want to trigger an action. To achieve this, I passed the selector with a subscription instead of passing an observable. selectedSchedulingsOnPopup$ = this.store.pipe(select(selectSchedulingsByBranch)); this.store.disp ...

Is the indigo-pink color scheme fully implemented after installing @angular/material and scss using ng add command?

After running ng add @angular/material, we are prompted to choose a CSS framework and theme. I opted for indigo-pink and scss. Will the material components automatically inherit this theme, or do we need to take additional steps? When using normal CSS (wi ...

Show ng-message when email is invalid in Angular Material without using ng-pattern

I need to show an error message that says Please enter valid email. when an invalid email is entered, but I cannot use the ng-pattern attribute with this specific regex pattern. <md-input-container class="md-block" flex-gt-xs> <label>Ema ...