Resizing and scrollable div element with the ability to adjust size from the left

My goal is to create a navigation bar on the left and content on the right. The current setup works well, but there is an issue with the scrollbar on the navbar pushing the resize icon inward by about 7 pixels. I am looking for a solution where the content pane can be resizable and the resize icon can be added to the west side, ensuring that the jquery will add a hidden resize div on the content side to position the resize icon correctly on the border.

Everything looks perfect without the scrollbar.

Image without Scrollbars

However, when scrollbars appear:

Image with the scrollbars

Below is the code I have implemented so far:

<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    <style>
        body {
            margin: 0;
            background-color: #222;
        }

        #nav {
            float: left;
            border-width: 0 5px 0 0;
            border-style: solid;
            background-color: yellow;
            width: 10%;
            height: 100vh;
            max-height: 100%;
            overflow-x: auto;
        }

        #content {
            background-color: brown;
            width: auto;
            height: 100vh;
        }
    </style>
    <script>
        $(document).ready(function() {
            $('#content').resizable({
                handles: 'e'
            });
        });
    </script>
</head>

<body>
    <div id="nav">This area should be scrollable and resizable with scrollbars always visible.
    </div>
    <div id="content">content</div>
</body>
</html>

If I can make the right side (content) resizable so the resize icon aligns with the resize border, while keeping the left side scrollable, both sides should resize as they currently do.

Answer №1

I successfully resolved the issue by applying jquery resizable to the "content" element. I also implemented a solution found on bugsdb which addresses resizing the navbar in reverse order.

   <style>
        body {
            margin: 0;
            background-color: #222;
        }

        #main {
            display: grid;
            grid-template-columns: 150px auto;
            height:100vh;
        }

        #nav {
            border-width: 0 0 0 0;
            border-style: solid;
            background-color: yellow;
            min-height: 100vh;
            overflow: scroll;
        }
        #insidenav {
            min-width: 400px;
            background-color: blue;
        }
        #content {
            background-color: brown;
            height: 100%;
        }
    </style>
    <script>
        $(document).ready(function() {

            //https://bugsdb.com/_en/debug/205a22489fadf5c1949aa1ac0400d691

            $.ui.plugin.add("resizable", "alsoResizeReverse", {

                start: function() {
                    var that = $(this).resizable( "instance" ),
                        o = that.options;

                    $(o.alsoResizeReverse).each(function() {
                        var el = $(this);
                        el.data("ui-resizable-alsoresizeReverse", {
                            width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
                            left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
                        });
                    });
                },

                resize: function(event, ui) {
                    var that = $(this).resizable( "instance" ),
                        o = that.options,
                        os = that.originalSize,
                        op = that.originalPosition,
                        delta = {
                            height: (that.size.height - os.height) || 0,
                            width: (that.size.width - os.width) || 0,
                            top: (that.position.top - op.top) || 0,
                            left: (that.position.left - op.left) || 0
                        };

                    $(o.alsoResizeReverse).each(function() {
                        var el = $(this), start = $(this).data("ui-resizable-alsoresize-reverse"), style = {},
                            css = el.parents(ui.originalElement[0]).length ?
                                [ "width", "height" ] :
                                [ "width", "height", "top", "left" ];

                        $.each(css, function(i, prop) {
                            var sum = (start[prop] || 0) - (delta[prop] || 0);
                            if (sum && sum >= 0) {
                                style[prop] = sum || null;
                            }
                        });

                        el.css(style);
                    });
                },

                stop: function() {
                    $(this).removeData("resizable-alsoresize-reverse");
                }
            });


            $('#content').resizable({
                handles: 'w',
                resize: function(event, ui) {
                }
            });

            $( "#content" ).resizable( "option", "alsoResizeReverse", "#nav" );

        });
    </script>
</head>

<body>
    <div id="main">
        <section id="nav">
            <div id="insidenav">
            This area should be scrollable and resizable with scrollbars on all the time.
        </div>
        </section>
        <section id="content">content
            <input type="button" id="winWidth" value="Width"/>
        </section>
    </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

Tips for verifying that one of the two input fields is filled in Bootstrap 5 validation

I have implemented Bootstrap validation for the other input fields in this form by using the 'required' attribute. However, for these two specific fields, if at least one is not empty, then the form should be submitted. <form class="needs ...

Tips for updating or refreshing a table in Rails using Actioncable

My Action Cable functionality is performing well, displaying an alert with the data content (although this alert appears on all pages). Here's the scenario: a user with the role of ADMIN can access a URL (http://localhost:3000/ventas/) that contains ...

How to maintain global position, rotation, and scale when adding an object to a group in Three.js

I need to transfer an object from one group (or world/scene) to another group while maintaining its global transformation. I want the object to appear unchanged. Here is an example of what I am trying to achieve: //store the current world transformation ...

Setting the value for a textbox using Jquery's .val() function works, while .attr() does not have the

//unable to get it working $("#TextBoxID1").attr("value","HI Value Change") //works perfectly fine $("#TextBoxID2").val("HI Value Change") <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> <input type= ...

Access an external URL by logging in, then return back to the Angular application

I am facing a dilemma with an external URL that I need to access, created by another client. My task is to make a call to this external URL and then return to the home page seamlessly. Here's what I have tried: <button class="altro" titl ...

Crafting a multidimensional array using a for loop in JavaScript: a step-by-step guide

I am attempting to dynamically create a multidimensional array at runtime like this: var terv=var people = [ { "name": "bob", "dinner": "pizza" }, { "name": "john", "dinner": "sushi" }, { "name": "larry", "dinner": "hummus" } ]; Here is an example ...

What is the reason behind utilizing the external 'this' within the inner function in Vue: $this=this?

Recently, I came across some code online that included a line $this=this. My initial interpretation was that this line assigns the 'this' of the outer function to a variable, allowing it to be used in the inner function as well. However, upon fur ...

Performing a AJAX POST call to the latest Google Analytics V4 API

Recently, the Google Analytics v4 API was updated and now requires POST requests instead of GET requests. Unfortunately, there are not many examples available yet... I managed to obtain the accessToken, but when I attempt the following POST request, I alw ...

iOS devices featuring the scroll function allows for seamless navigation and effortless

Here is the code snippet that I am using: $(document).scroll(function() { thedistance(); }); I would like thedistance() to trigger while a user is scrolling on an iOS device, however, it currently only fires after the scrolling has stopped, rather t ...

Retrieve all documents from a Firebase User's collection

Recently, I created a Firebase cloud function where my goal is to access every user's internal collection named 'numbers' and examine each document within that collection for some comparisons. Do you have any insights on how I can achieve t ...

Struggling with configuring a personalized version of Bootstrap 4 in Sass

I am currently in the process of creating a custom version of Bootstrap 4. One of the main changes I want to make is switching the default color ("primary") from Bootstrap Blue to something different. Initially, I made the edits directly to the Bootstrap ...

Is it possible to make the home page of a Next.js app in a subfolder with basePath accessible outside of the basePath?

My Next.js application is running in the '/portal/' folder and basePath has been configured as: module.exports = { basePath: '/portal' } Now, I want the index page of the application to be accessible at the site root (without baseP ...

Arranging multiple Label and Input fields in HTML/CSS: How to create a clean and

I'm struggling with HTML and CSS, trying to figure out how to align multiple elements on a page. I've managed to line up all the rows on the page, but for some reason, the labels are appearing above the input fields when I want them to appear be ...

Get the redirectUri using npm's Request package

When using npm Request to generate a response, I am able to retrieve information like "statusCode" by using "response.statusCode". However, I am unable to retrieve other information such as "redirectUri" as it shows undefined. Is there a way to access the ...

When using React's setState function, it sometimes fails to re-render with the most up-to-date data and instead shows

Encountering an issue with my class component where the state is not updating with the current user value on click, but rather displaying the previous value before updating. For example, if the initial value is set to 0 and I try to update it to 20 on clic ...

Displaying Bootstrap Modal when text box is empty in Blazor Server application?

What is the process for displaying a Bootstrap Modal popup when a text box is empty in Blazor Server? ...

The most effective method for creating a native mobile app (for iOS, Android, and more) is by utilizing an existing AngularJS

I developed a cutting-edge AngularJS application utilizing various plugins like angular ui-router, angular-translate, and bootstrap 3. While the app runs smoothly on web browsers of desktops/laptops and smartphones with built-in browsers, I have concerns ...

Tips for iterating through nested objects with a for loop

Struggling with validations in an Angular 5 application? If you have a form with name, email, gender, and address grouped under city, state, country using FormGroupname, you might find this code snippet helpful: export class RegistrationComponent implemen ...

Is it possible to insert an image directly into the <img> tag without having to first send it to the server?

I've created an upload form that allows users to submit images: <form> <input accept="image/jpeg, image/gif, image/png" type="file" name="image" id="image" class="UploadInput" onchange="submitImageUploaderForm()"/> </form> Once t ...

What is the best way to perform calculations within a PHP loop for <input> elements and then display the results using a JavaScript loop?

Hello everyone, I'm currently struggling with displaying the calculations from a loop of input tags. What I'm trying to achieve is having 5 rows with input fields. At the end of each row, there should be a span area that displays the calculation ...