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

Deactivate a button when clicked on a card that has been mapped

After creating a card component and mapping through each card, I added an onClick function to disable the button of the clicked card. However, my logic ended up disabling all buttons instead. Here is the code snippet where I define the rendering of the UI ...

Implementing pagination in React: A step-by-step guide

I am fetching data from the GitHub API, specifically from here Although I have all the necessary data to display, I want to limit it so that only 20 repositories are shown per page. In addition, I prefer not to use any frameworks or plugins for this task ...

Looking to preview files on a server before downloading them? If you're getting the error message "Not allowed to load local resource: blob,"

Update: To clarify, we are using <embed #reportPdf width="100%" height="800"> and: this.pdf.nativeElement.src = this._window.URL.createObjectURL(this.re); It functions properly on Safari and Firefox. However, when loaded on Chrome, it displays as ...

Struggling with parameter passing issues and preparing code for seamless integration with MYSQL database

I've been dedicating the past four days to a project that I've crafted entirely by hand to test my JavaScript skills as I progress through Codecademy courses. The goal is to develop a browser-based checklist program, and so far, I've success ...

What is the best way to connect a relative CSS stylesheet to a master page?

My Java application generates several HTML pages, organized in different directories: html_pages/ | ----> landin_page.html html_pages/details | ----> index1.html html_pages/more_details | ----> index2.html html_pages/css | ...

Typescript - Interface containing both mandatory and optional properties of the same type

Looking for a solution where an interface consists of a fixed property and an optional property, both being of type string. export interface Test{ [index: string]: { 'list': string[]; // <<< throws TS2411 error [in ...

Mathematics - Determined the dimensions of an adjusted image size

Currently, I am implementing a basic mathematical method to crop an image. My approach involves utilizing the jQuery plugin called imageareaselect.js to overlay an adjustable layer on top of an image. By resizing this layer with the cursor and clicking a b ...

HTML control for adjusting the pan and tilt of a device

I'm looking to develop an interactive input where users can drag a dot within a box and see the 2D coordinates of that dot displayed. The goal is to use this feature to control pan and tilt values. A similar functionality from another application is s ...

How can I add a channel to a category using await(discord.js)?

Having trouble organizing a new channel within a category. The .setParent(categoryID) method seems to only work with existing channels, causing an issue when I attempt to execute my code. Take a look at the code snippet below: client.on("message" ...

Navigating a relative path import to the correct `@types` in Typescript

When the browser runs, I require import * as d3 from '../lib/d3.js'; for d3 to be fetched correctly. I have confirmed that this does work as intended. However, the file that contains the above code, let's call it main.js, is generated from ...

Attempting to resolve the Bootstrap issue, currently in search of a suitable solution

Today I made the decision to utilize bootstrap to create a menu, but unfortunately, I've encountered a strange bug or conflict involving jQuery, potentially the UI, and Bootstrap. If you'd like, you can take a look at the picture provided in the ...

I'm currently working on a React toaster component, but I'm facing an issue where it's not displaying

I have created the Toaster component programmatically and I am passing the message through another component. This is how my Toaster component looks: export default class MyToaster extends React.Component { constructor(props) { super(props); ...

A guide on handling and presenting an array of objects using AngularJS

I am currently working on a project where I have a large array of objects that need to be filtered, processed, and then displayed to the user. The application is built using node-webkit and I am using AngularJS and jQuery for routing, DOM manipulation, and ...

Is there time support in the Angular 2 material date picker?

I recently upgraded to angular material version 2.0.0 beta.12 Although the <mat-datepicker> is functioning properly, I am interested in adding an option to select the hour (time) along with the date. After searching through the components listed on ...

Integrating React js with Layout.cshtml: Mastering the Fusion of React Routing and ASP.NET MVC Routing

My current project involves an ASP.NET MVC core application with the View written in cshtml. The routing follows the conventional asp.net mvc routing pattern. However, I've recently implemented a new module using React JS. Now, I'm faced with the ...

Creating an interactive Table of Contents in Sharepoint using only JavaScript

Imagine you have a massive Sharepoint wiki page filled with various heading tags like H1, H2, H3, and H4 - now picture creating a dynamic Table of Contents using these tags. The goal is to categorize these tags by group and utilize the HTML <detail> ...

Show the current time using Moment.js

I am currently working on developing a clock component that displays the current time in real-time. Issue: The initial time is correctly displayed when the page loads (HH:mm A), but the clock does not update dynamically. clock.component.ts : import { ...

End the primary division post button activation within Angular 2

Is there a way to close the main div upon clicking a button that is located inside the same div? Below is my code snippet: index.html <div id="main"> <button type="button">Click Me!</button> </div> hello.component.ts import ...

What methods can be used to reveal the true value of data that has been encrypted?

Is it possible to retrieve the original value of data that has been hashed? Can the hashcode be reversed to reveal the real value of the data? String ida = new String(txtID.getText().toString()); int idb = ida.hashCode(); codeD.setText("result: " + ida) ...

Tips for refreshing the value of a dependency injection token

When using Angular dependency injection, you have the ability to inject a string, function, or object by using a token instead of a service class. To declare it in my module, I do this: providers: [{ provide: MyValueToken, useValue: 'my title value& ...