Restrict Scrolling on Large Screens with Bootstrap, Allow Scrolling on Medium or Smaller Screens

I have a website that utilizes the Bootstrap 4 framework (v4.4.1). I implemented CSS properties height: 100% in HTML and body along with overflow: hidden to restrict scrolling and keep the content within the browser window only (I don't have much content). (I am aware of using the h-100 Bootstrap CSS class).

Now, I want to allow scrolling on mobile screens (considered as MD breakpoint or smaller). How can I achieve this in a Bootstrap-friendly manner? One traditional approach could be to dynamically remove height: 100% and overflow: hidden during onLoad() events and when the browser is being resized, but it may not align with the Bootstrap methodology.

The following are the basic code snippets:

HTML section (only body part)

<div class="container-fluid h-100">
    <div class="row h-100 justify-content-center align-items-start">
        <div class="col-12 col-sm-8 h-100 bg-info text-center" id="page1">
            <p>
                Page 1<br />
                <span class="btn btn-success" id="btn_page2">To Page 2</span>
            </p>
        </div>
        <div class="col-12 col-sm-8 h-100 bg-warning" id="page2">
            <p>
                Page 2<br />
                <span class="btn btn-success" id="btn_page3">To Page 3</span>
            </p>
        </div>
        <div class="col-12 col-sm-8 h-100 bg-info" id="page3">
            <p>
                Page 3
            </p>
        </div>
    </div>
</div>

CSS styles

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Bebas Neue', cursive;
    background-color: #000;
    color: #FFF;
    margin: 0;
    padding: 0;
}
#page2, #page3 {
    display: none;
}

Javascript to demonstrate functionality (not directly related)

$(document).ready(function() {
    $('#btn_page2').click(function() {
        $('#page1').hide();
        $('#page2').show();
        $('#page3').hide();
    });
    $('#btn_page3').click(function() {
        $('#page1').hide();
        $('#page2').hide();
        $('#page3').show();
    });
});

JSFiddle demo: https://jsfiddle.net/shivanraptor/xdj1f35e/15/

I aim to enable the effect where Page 1, 2, and 3 are displayed one after another vertically and scroll seamlessly like an extended webpage on screens at MD breakpoints or smaller sizes.

Answer №1

To avoid using h-100, I recommend using min-vh-100 for the "pages" section. This way, you only need a @media query for the body overflow without requiring any JavaScript:

@media (min-width: 576px) { 
  body {
      overflow: hidden;
  }
}

Answer №2

To achieve the desired functionality, consider implementing the following script:

$(window).on('load resize', function () {
    if ($(window).width() < 768) {
        $('#page1, #page2, #page3').show();
      $('.btn').hide();
    } else {
        $('.btn').show();
      $('#btn_page2').click(function() {
          $('#page1').hide();
          $('#page2').show();
          $('#page3').hide();          
      });
      $('#btn_page3').click(function() {
          $('#page1').hide();
          $('#page2').hide();
          $('#page3').show();
      });
    }
});

In addition, apply the corresponding styles using CSS:

@media (max-width: 767.98px) { 
  html, body {
    height: 100%;
    overflow: initial;
  }
}

@media (min-width: 768px) { 
  html, body {
      overflow: hidden;
  }
}

Note that the MD size refers to tablets with a width of 768px or below as per Bootstrap documentation.

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

Is there a way to determine if a string is empty, even if it contains hard returns?

I am currently working on a function that checks if a string is empty or not, but it seems to be missing the detection of new lines. export const isStrEmpty = function(text: string): boolean { return !text || text.match(/^ *$/) !== null; }; I attempted ...

Reorganizing Rows with JQuery DataTables

I've been working on a function to swap rows in a table, but for some reason, it's not functioning as expected. The data within the rows doesn't align properly with the array information. I could really use some help identifying any errors i ...

Absolute positioning in Tailwind CSS on an absolute div

I'm having trouble incorporating 4 absolutes within this div. I can't seem to figure out why they are extending beyond the boundaries of the div. Can anyone spot the error? Check out this Tailwind CSS example <div class="bg-blue-100 h-40 ...

Is it feasible to incorporate one iOS app within another iOS app through in-app purchasing or subscription?

Simply put, we are creating interactive content in Flash that we want to distribute through an iOS app either by in-app purchase or subscription. In our testing, we have found that Flash can produce standalone iOS apps that work well for our needs. Instea ...

Is there a way to incorporate multiple plan tiers on Stripe's platform?

//api/stripe import { auth, currentUser } from "@clerk/nextjs/server"; import { NextResponse } from "next/server"; import { prismadb } from "@/lib/prismadb"; import { stripe } from "@/lib/stripe"; import { absoluteUr ...

What is the process for transferring an image from the main page to another?

For days, I have been searching for an answer without any luck. It seems that I just can't wrap my head around it and apply it to what I am working on. Currently, I am using PHP to store images on the server when a user hits submit. My goal is to dis ...

Duplicate the canvas onto a new canvas

One of the functions I am using involves copying an old canvas to a new canvas. Here is the code snippet for this functionality: function cloneCanvas(oldCanvas) { //create a new canvas var newCanvas = document.createElement('canvas&a ...

Encountering a timeout issue with the Sinch API within an Angular 2 project during the onCallProgressing

We successfully integrated Sinch into our angular 2 web application. Most functionalities are working perfectly, except for the user calling feature using the sinch phone demo. When the application is in the foreground, the call rings and connects withou ...

Transform special characters into HTML entities

$scope.html = '&lt;script&gt;'; Is there a way for Javascript to convert &lt;script&gt; back to <script>, similar to how PHP does it? ...

Positioning CSS for a Responsive Button

Currently, I am working on making my modal responsive. However, I am encountering an issue with the positioning of the "SAVE" button. The button is not staying in the desired position but instead disappears. Below is the snippet of my HTML and CSS: .dele ...

Trigger a re-render of specific components upon clicking a button in React

Within my server file, there is a function that retrieves a specific set of data based on an ID. app.get('/musicbyid', function(req, res){ var query = req.query.term.toLowerCase(); music.find({ _id: query }, function(err, allMusic){ ...

The min-height property in Bootstrap 3 causes a div element to not expand as expected

Having a bootstrap 3 page with a centered box that contains content, I noticed that the box does not expand when the content grows. The bootstrap container grows, but the box remains static. I have tried using "position:relative" and "overflow:hidden", as ...

Guidance on loading JSON array information into highcharts using AngularJS

I am working on a project in Play Framework (play-java) where I need to display a bar graph using Highcharts. The Java API returns data in JSON format with a field called 'name' containing values like 'Data', 'Gadgets', ' ...

Generate all conceivable combinations of elements found in the array

Looking to generate all possible combinations of elements (without repetition) from a given array and length. For example, with an array of: arr = ['a','b','c','d'] and a length of 3, the desired output would be a ...

Show a FlatList horizontally within a schedule-themed scroll view element

Below is an illustration of the desired component. It features a schedule-like screen with a vertical scroll view for transitioning between time stamps and a FlatList for horizontal scrolling through items. Picture this as a weekly timetable for a gym, dis ...

Encountering a reference error with jQuery following the installation of jQuery DateTimePicker (unofficial) within an Angular project

During the development of my Angular project, everything was functioning smoothly without any hiccups until I decided to integrate the jQuery DateTimePicker plugin called Clean jQuery DateTimePicker. Prior to adding the DateTimePicker, jQuery was seamless ...

Issue encountered when integrating JavaScript into Django view form update

I have successfully implemented a Django view to add an invoice to my application, complete with added JavaScript functionality that is functioning properly. <p> <label for="id_total_without_vat">Price</label> <input ...

The functionality of the Dropdown feature may present limitations in Laravel Blade, however, it performs excellently on any other text

There seems to be an issue with the dropdown functionality in Laravel Blade. It works as expected in other editors, as you can see from the code below. I am using Bootstrap 5.0.2 <!DOCTYPE html> <html lang="en"> <head> <meta ...

JavaScript autostop timer feature

An innovative concept is the solo cookie timer that holds off for one hour before resuming its function upon user interaction. No luck with Google. https://jsfiddle.net/m6vqyeu8/ Your input or assistance in creating your own version is greatly appreciate ...

Revamp the bootstrap Tooltip.prototype.fixTitle() override function

Hey there, I have a question regarding the Bootstrap tour that I'm using on my website. I want to customize the following method: Tooltip.prototype.fixTitle = function () { var $e = this.$element; if ($e.attr('title') || typeof ($ ...