What is the best way to incorporate a horizontal scroll bar that remains fixed at the bottom of the screen?

Within my main container, I have a div that has a height fitting perfectly into the main container but a width wider than the main container with an overflow for the horizontal scroll bar.

The challenge that I am facing is: 1. Instead of requiring the user to scroll to the bottom of the page and then use the horizontal scroll bar, I would like the horizontal scroll bar to be fixed at the bottom of the view (not within the div).

  1. Upon loading, I want the horizontal scroll bar to be visible at the bottom of the user's screen. As the user scrolls down, the horizontal scroll bar should move down the page until it reaches the bottom where it will remain at the bottom of the div (not the window).

Any assistance on this matter would be greatly appreciated.

Thank you.

http://codepen.io/seraphzz/pen/LBIsf

Answer №1

Here is my approach:

    function begin() {
      // Let's determine our requirements
          /* Window's height */
        var bodyHeight     = document.body.offsetHeight;
           /* Window's width */
        var bodyWidth     = document.body.offsetWidth;
          /* Table container */
        var myTable         = document.getElementById('tablefixed');
          /* Table container's height */
        var tableHeight   = myTable.offsetHeight;
          /* Content */
        var content =document.getElementById('gotainer');  
          /* Let's focus on layout */
        var col1Width    = 250;
        var tableWidth = 400;

          // Adjust values accordingly
        if (bodyHeight < tableHeight) 

               { /* If body's height is less than table */
                  content.style.height = tableHeight+ 20 +'px';
                  window.onscroll = function() {scrolling();    }
               }
        else 
               {
                  myTable.style.height =  bodyHeight+'px';
               }

         /* Keep an eye on col1 & col2 to stay within screen and cover full height */
        var column1 = document.getElementById('col1');
        var column2  =document.getElementById('content');
          /* Limit width */
        column2.style.width = bodyWidth - col1Width - tableWidth -50 +'px';
          /* Set height if CSS doesn't */
        //column1.style.height= content.offsetHeight+'px';
        //column2.style.height= content.offsetHeight+'px';
    }

    function scrolling() {
    function scrolling() {
if(!window.pageYOffset) {
     var pageScroll = document.getElementById('scrolling').scrollTop;  
     }

else {
    var pageScroll = window.pageYOffset;
      }
    var content =document.getElementById('gotainer');
    var tableContainer = document.getElementById('tablefixed');
    tableContainer.style.margin='-'+pageScroll+'px 0  0';
} 
        var content =document.getElementById('gotainer');
        var tableContainer = document.getElementById('tablefixed');
        tableContainer.style.margin='-'+pageScroll+'px 0  0';
    }


    window.onload     = begin ;
    window.onresize   = begin;
    window.onscroll   = scrolling;

Please note:(in case you missed it) - this code is for beginners.
View my codepen http://codepen.io/gcyrillus/pen/CHfAb It also works with Firefox.

Answer №2

A simple and user-friendly solution for creating custom scrollbars that work seamlessly on desktops, tablets, and phones.

This tool is compatible with DIVs, IFrames, textareas, and even the overall document page (body) scrollbars.

Whether you need horizontal or vertical scrolling, this solution has got you covered.

Find out more by visiting:

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

Having trouble with your jQuery code not loading properly?

Currently working on debugging jQuery code and facing an issue where a particular section of the code is not being triggered upon clicking. The HTML/PHP in question: $cartlink .= "<a class='add_to_cart button' data-id='{$product->id} ...

AngularJS dynamic data table for interactive and flexible data presentation

I am looking to implement a dynamic data table using AngularJS, with the first column containing checkboxes. The data will be in JSON format as shown below, $scope.items = [ { "id": "1", "lastName": "Test1", "firstName": "Test", "email": "<a hr ...

Unable to utilize the .keyCode method within a query selector

Trying to utilize .keyCode in JavaScript to identify a pressed key, but the console consistently displays null after each key press. Below is the relevant CSS code: <audio data-key="65" src="sounds\crash.mp3"></audio> ...

Having trouble with jQuery's 'OR' not functioning properly when iterating through mandatory input elements

In the process of creating a fallback for required HTML5 attributes for different input types, I encountered an issue with checking the ':checked' status of radio buttons and using the 'OR' || operator within the loop: if (self.val() = ...

Can a gradient box arrow be created using CSS 3?

Check out the following link to see a green box with a left-pointing arrow that floats: Is it achievable using solely CSS3? Can the arrow shape and gradient be created to appear in both the box and the arrow? If yes, how would you go about achieving this ...

What is the best way to prevent text overflow in a div while maintaining its width without dropping down

I have a square element that measures 100 pixels in width. The overflow-x property has been applied, with a value of hidden. My intention was for this setting to conceal any text that extends beyond the boundaries of the container, rather than allowing it ...

Delete the parent div when the button is clicked

trying to create a dynamic button system to add/remove inputs on clicks. I have the addButton working but not the deleteButton. What am I missing? $(document).ready(function() { var maxFields = 20; var addButton = $('#plusOne'); va ...

Issue encountered: Inoperable binding when employing ko.mapping with two distinct models

I've been struggling to implement a drop-down select in conjunction with a table on a page using knockout bindings. The issue arises when I try to use the mapping options in the knockout binding plugin – either the drop-down or the table behaves inc ...

Arranging extensive menu sections and content containment

I am currently working on enhancing my website's navigation by creating a mega menu. However, I am facing issues with the organization of the divs containing the ul content. In the fiddle linked below, you can see that "Africa", "Asia", and "Oceania" ...

Utilize Bootstrap to occupy the rest of the available vertical space

Struggling with handling empty space in a Bootstrap grid? Check out the issue I'm facing when the div doesn't fill the entire height. https://i.sstatic.net/zvS7t.png This is the current configuration: <div class="row"> <div class= ...

Codeigniter Implementation of Ajax File Upload

I'm having a bit of trouble with uploading an image using codeigniter and ajax. I already have my ajax method set up to insert field values into the DB, but I'm not sure about the best approach for uploading the file itself. Below is a custom JQu ...

The AJAX request to the GitHub OAuth API using jQuery encountered an unknown issue and returned an unexpected error

Let me start by sharing the following code snippet: var requestAuthUri = 'https://github.com/login/oauth/access_token'; var ajaxArgs = { type : 'POST', url : requestAuthUri, headers : { &ap ...

Enhance video playback by eliminating accidental scrolling through the space bar

When using a video player, I always prefer to pause it by pressing the spacebar. However, this function is not working as expected. The issue at hand is that instead of pausing the video, pressing the space bar causes the page to scroll down unexpectedly ...

Discovering a collection of class elements with particular text in Selenium IDE

My objective is to verify that the correct title, summary, and link are displayed in search results. In the scenario below, I aim to ensure that one of the listings includes the title "Title for Beta," a summary with the content "Summary for Beta," and a ...

What method can be employed to eliminate choice selection lacking any value?

Currently, I am encountering difficulties in my attempt to remove or hide the first option value from a ransack code. Would you be able to assist me in addressing this concern? Here is the HTML CODE that I am working with: <select id="q_c_0_a_0_name" ...

Efficiently handling multiple form submissions using a single jQuery Ajax request

I'm working on a page that has 3-4 forms within divs, and I want to submit them all with just one script. Additionally, I want to refresh the content of the specific div where the form is located. However, I'm unsure of how to specify the current ...

Create a spectrum of vibrant colors depending on the numerical value

I'm attempting to create a function that generates rainbow colors based on a numerical value. var max = 10000; var min = 0; var val = 8890; function getColor(min, max, val) { // code to return color between red and black } Possible Colors: Re ...

Remove any elements using jQuery that do not contain any content

I need to remove any empty elements from my HTML code. Here is an example of the HTML markup: The HTML markup is stored in a jQuery variable called 'myhtml' and it may contain various tags. <h1> <u> <strong></st ...

Checkbox selection limitation feature not functioning correctly

Having trouble with my checkbox question function - I want to limit the number of checkboxes that can be checked to 3, but it's still allowing more than that. I suspect the issue lies with latestcheck.checked = false; This is my typescript function: ...

What steps should I take to troubleshoot and fix the issue of data insertion errors in

https://i.sstatic.net/VccFk.jpg I am encountering an issue with a PHP form that is supposed to transfer information to a database after submission. However, every time I press the submit button, I receive an error message. Can anyone help troubleshoot th ...