Is it possible to drag the div container in HTML to resize its width from both left to right and right to left?

After posing my initial inquiry, I have devised a resizing function that allows for the expansion of a div's width. When pulling the right edge of the div to resize its width from left to right, is it possible to adjust the direction or how to resize it from right to left?

See an example of drag resizable image

drag-resizable-container.component.html

<div id="resizer-container">
  <!-- [style.width.px]="width" [style.height.px]="height" [style.transform]="'translate3d(' + left + 'px,' + top + 'px,' + '0px)'" -->
  <div id="content-container" [style.width.px]="width" [style.height.px]="height" [style.transform]="getTranslate3D()">
    <ng-content></ng-content>
  </div>
  <div #graberWidth id="grabber-width" [ngStyle]="getGrabberDirection()" (pointerdown)="onMouseDown($event)" (pointerup)="onMouseUp($event)"></div>
</div>

drag-resizable-container.component.scss

div#resizer-container {
  display: flex;
  flex-flow: row nowrap;

  div#grabber-width {
    width: 8px;
    height: 100%;
    position: absolute;
    cursor: col-resize;
  }
}

drag-resizable-container.component.ts

import { AfterViewInit, Component, ElementRef, HostListener, Input, OnInit } from '@angular/core';

@Component({
  selector: 'app-drag-resizable-container',
  templateUrl: './drag-resizable-container.component.html',
  styleUrls: ['./drag-resizable-container.component.scss'],
})
export class DragResizableContainerComponent implements OnInit, AfterViewInit {

  @Input() public width: number;
  @Input() public height: number;
  @Input() public resizeWidth = true;
  @Input() public resizeHeight = false;
  @Input() public left = 0;
  @Input() public top = 0;
  @Input() public expandDirection: 'LEFT' | 'RIGHT';
  @Input() public boxSpec = { left: 0, top: 0 };
  @Input() public willSetParent = false;
  @Input() public willSetParentofParent = false;
  public isResizing = false;

  private mouse = { x: 0, y: 0 };
  private reqireInitWidht = false;
  private reqireInitHeight = false;

  constructor(
    private elementRef: ElementRef
  ) { }

  ngOnInit() {
    if (!this.width) {
      this.width = 300;
      this.reqireInitWidht = true;
    }
    if (!this.height) {
      this.height = 300;
      this.reqireInitHeight = true;
    }
  }

  ngAfterViewInit() {
    const elem = this.elementRef.nativeElement as HTMLDivElement;
    setTimeout(() => {
      if (this.reqireInitWidht) {
        if (this.willSetParentofParent) {
          this.width = elem.parentElement.parentElement.clientWidth;
        }
        else {
          this.width = elem.parentElement.clientWidth;
        }
      }
      if (this.reqireInitHeight) {
        if (this.willSetParentofParent) {
          this.height = elem.parentElement.parentElement.clientHeight;
        }
        else {
          this.height = elem.parentElement.clientHeight;
        }
      }
    }, 500);
  }

  private updateWidthHeight(element: HTMLDivElement, width: number, height: number) {
    // Update width and height based on resizing options

  }

  @HostListener('window:mousemove', ['$event'])
  onMouseMove(event: MouseEvent) {
    // Perform resizing calculations during mouse movement

  }

  onMouseDown(event: MouseEvent | Event) {
    this.isResizing = true;
  }

  onMouseUp(event: MouseEvent | Event) {
    this.isResizing = false;
  }

  getTranslate3D() {
    return 'translate3d(' + this.left + 'px,' + this.top + 'px,' + '0px)';
  }
  
  getGrabberDirection(){
    return this.expandDirection === 'LEFT' ? { right: '0px' } : { left: '0px' };
  }

}

Answer №1

Resizing from left-to-right is generally more common and practical, particularly for elements like the navigation bar.

It may be wise to avoid offering the option to resize from right-to-left in most cases.

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

Using Angular - Executing a query only when a URL parameter is present

Can I execute this query only if a URL parameter (paramOne) is present? queryAndSubscribe(){ this._subscription = this._activatedRoute.params.pipe( tap (params => { console.log('params = ', params); }), switchMap ...

When the drawer is opened, there is a strange phenomenon of all buttons being mysteriously clicked

Currently, I am working on a single-page web application utilizing React and Material UI, along with React-Mini-Router for routing. The app features a side drawer that is activated by clicking a hamburger icon located in the top app bar. Each item in the d ...

Using ngFor to loop through an array of objects and calculate the number of elements in an array property

Currently I am developing a web application using Angular 6. The data is obtained in the form of an array of objects from Firebase, and my intention is to present this information to the user by utilizing ngFor. export interface Competition { createdAt: ...

Potential breakpoint (Breakpoint established but not yet linked)

My experience with debugging my Angular app in Chrome was going smoothly through the Chrome Debugger extension with automatic settings. However, something changed after a Windows 7 reboot and all my breakpoints became inactive. I suspect this was due to a ...

reduce opacity of specified div background

Objective / Purpose I am working with multiple div elements and I want to assign two distinct classes to each of them, each serving a different purpose within my application. One class should determine the level, influencing the color of the div. The oth ...

Restrict the number of subscriptions allowed for an rxjs observable

Seeking a replacement for observable, subject, or event emitter that allows only one subscription at a time. The first subscriber should have priority to execute its subscribe function, with subsequent subscribers waiting their turn until the first unsubsc ...

Always display all options in MUI Autocomplete without any filtering

I am seeking to eliminate any filtering in the MUI Autocomplete component. My goal is for the text field popper to display all available options. The results are obtained from a server-side search engine. These results, or "hits," already provide a filter ...

Enabling block scrolling on a parent element using jscrollpane functionality

Is it possible to set up a jscrollpane so that the parent pane doesn't scroll when the child scroll has reached its bottom? Currently, when the child scrolling reaches the bottom, the parent also scrolls. I would like the parent to only scroll when th ...

React Native error - Numeric literals cannot be followed by identifiers directly

I encountered an issue while utilizing a data file for mapping over in a React Native component. The error message displayed is as follows: The error states: "No identifiers allowed directly after numeric literal." File processed with loaders: "../. ...

jQuery load() function triggers unexpected error in jQuery plugin

Here is the current structure of my page: <body> <div id="menuBar"> </div> <canvas id="myCanvas" width="700" height="700" style="border:1px solid #000000;"></canvas> </body> <script src="../Scripts/jQuery.mazeBo ...

"Looking for a solution to the ESLint error related to 'no-unused-var' and Google Maps integration. How can I effectively resolve

I'm struggling with what seems to be a simple problem I tried adding /* export myMap */ or /* global myMap */ at the beginning of the script but I keep getting errors Code HTML <h1>My First Google Map</h1> <div id="googleMap" ...

Using JavaScript promises to handle connection pooling and query execution

I am contemplating whether this approach is on the right track or if it requires further adjustments. Should I consider promisifying my custom MySQL getConnection method as well? request: function(queryRequest) { return new Promise(function(re ...

Is there a way to allow only the block code to shift while keeping the other span tags stationary?

Is it possible to change the text without affecting other span tags in the code? I want to make sure only this specific text is updated. How can I achieve that? var para_values = [ { content: "BRAND " }, { content: "MISSION" } ]; functi ...

The symbol 'router-outlet' is not recognized by the system

This new project utilizes Angular 13 for its implementation. One of the key updates is the addition of routing to the project, specifically in the file app-routing.module.ts. import { NgModule } from '@angular/core'; import {RouterModule, Routes ...

What is the best way to adjust a <div> element so that it stays centered on the webpage while also keeping its size attributes intact?

"How To" Can you help me center a single element within a "div" on my webpage without changing its current size attributes? Here is the page I need assistance with: I would like the "Interior Painting" element under the "Residential Services" header to ...

How can I implement a jQuery slide down effect for a specific individual instance?

Whenever I click on the "Share your thoughts" button, the comments block slides down for every section instead of just the particular section I clicked on. Is there a way to make it so that only a single block slides down when the button is clicked, regard ...

Tips for organizing a Material UI DataGrid table effectively while keeping the total sum rows within the DataGrid unaffected

Check out my codeSandbox link here: https://codesandbox.io/s/making-sum-of-column-in-datagrid-mui-zjzfq6?file=/demo.js I've noticed that when I sort by ascending, the subtotal, total, and tax rows move up, but when I sort by descending, they move dow ...

What is the process for creating a unit test case for an Angular service page?

How can I create test cases for the service page using Jasmine? I attempted to write unit tests for the following function. service.page.ts get(): Observable<Array<modelsample>> { const endpoint = "URL" ; return ...

Basic Hover Effect in Javascript

Looking at this snippet of HTML: <div id="site-header-inner"> <div id="header-logo"> <?php echo wp_get_attachment_image(get_field('header_logo','options'),'full'); ?> </div> <div id= ...

The message of error is undetermined

Can someone help me with using the errorMessage object from routes in a partial? I have attempted to implement it as shown below: Route:- const express = require("express"); const router = express.Router(); const Character = require("../models/character" ...