Problems with scrolling on mobile devices

So here is the issue I am facing:

  • The layout is optimized for mobile with a max-width of 480px. I have a menu which includes options like login, register, and cart, all of which have dropdowns. Since the height of these dropdowns is dynamic, I need to calculate their height and prevent users from scrolling below that element.

For instance - Let's say .class has a height of 900px, I want to restrict users from scrolling below that height. So when the viewport or window reaches the end of that .class, the user should not be able to scroll down further.

Below is the code where I attempted to achieve this using the scrollTop function.

var limitScroll = false;

$(window).scroll(function() {
    if(limitScroll && $(this).scrollTop() > limitScroll) {
        $(this).scrollTop(limitScroll);
    }

});

// Opening box-container
$('.top-menu li a.links').click(function(event){
    event.preventDefault();
    $('.box-container, .sub-menu').removeClass('opened');
    $(this).next().addClass('opened');

    var c = $(this).next();
    limitScroll = c.outerHeight()-$(window).height()+c.offset().top + 20;

});

Here is a preview of the mobile layout and dropdowns.

https://i.sstatic.net/kB2ST.pnghttps://i.sstatic.net/2Axed.png

Answer №1

An improved strategy would be to activate the dropdown as a full-screen div. Displaying this div upon button click:

<div id="login>...</div>

Custom styles

#login{
    height:100%;
    min-height:100%;
    width:100%; 
    position:absolute;
    z-index:999;
}

Now, the div covers the entire site, allowing the user to close it with the "close" button without any scrolling issues ;)

UPDATE: Another option is to customize the li of that dropdown to occupy the screen size.

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

Synchronizing client information in real-time: tips, tricks, and expert advice

Currently, I am developing a PHP backend and utilizing JS/Jquery for the front end of an application that aims to facilitate near real-time communication among users. My main concern right now is determining the most effective approach to achieve this goal ...

` `$(document.documentElement) selecting a particular element` `

Here is a function that I am working with: jQuery(document.documentElement).on('click touch', function(e) { // check if $(e.target) matches with $('ul#menu-navigation > li.menu-item') // or any child elements within this spe ...

"Troubleshooting: Why Won't My Entire Div Display on the

Struggling with a website rebuild due to my limited knowledge of HTML/CSS. For some reason, this whole div section isn't showing up as it should. Here is the problematic div: <div class="container clearfix"> <div class="border-shade sli ...

Disabling Ajax navigation in jQuery Mobile is essential for uploading images smoothly

I am having difficulty disabling Ajax navigation in my form by using data-ajax="false". Where should I place this? <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>textinput& ...

iPhone Safari Mobile Browser experiencing issues with sms: and mailto: functionalities

Issue: Encountering a problem with web pages containing sms: and mailto: links not functioning on iOS mobile Safari browser. Clicking on the link redirects to: Safari cannot open the page because it cannot redirect to locations starting with "sms:& ...

AJAX in jQuery is failing to send data

I am facing an issue with sending key and value pairs to a PHP file using jQuery's AJAX function. Despite my efforts, the function does not seem to be sending the data. Both the PHP code and the HTML code are present in the same "Tester.php" file, as ...

Error message: "When using Webpack 4 with Bootstrap, a TypeError occurs where property 'jquery' is read as undefined."

I've recently delved into the world of webpack and everything seems to be running smoothly. However, when I run my webpack app, I encounter the following error within Bootstrap: var version = $.fn.jquery.split(' ')[0].split('.'); ...

Guide to customizing the CSS styles of various components within a Material UI Dialog

Let's take a look at this snippet for creating a Material Dialog in code: <Dialog open={this.props.open} onClose={this.props.closeAtParent} PaperProps={{ style: { minHeight: '75vh', minWidth: '75vw', ...

Creating a JSON schema in JavaScript using an already established JSON framework

I have a json structure stored in a variable called "data" that looks like this: { "SearchWithMasterDataDIdAndScandefinitionDAO": [ { "dateDm_id": 20120602, "issueValue": "ELTDIWKZ", "scanName": "Company Stored as Person (Give ...

Promise.allSettled() - Improving resilience through retry mechanisms for concurrent asynchronous requests

TL;DR: I'm seeking advice on how to handle multiple promise rejections and retry them a specified number of times when using Promise.allSettled() for various asynchronous calls. Having come across this article: I was intrigued by the following state ...

Tips for shifting a designated row upward in Chrome using JavaScript

Currently, I am working on a Javascript function that moves up a selected row. However, the issue I am facing is that when the row moves up, the old row is not being removed. For instance, if I move up the 'bbbb' row, it successfully moves up bu ...

Dynamic SVG positioning

Looking for a way to make this svg shape relative to its containing div? Fiddle: http://jsfiddle.net/8421w8hc/20/ <div> <svg viewBox="0 0 1000 2112" style="" xmlns="http://www.w3.org/2000/svg" version="1.1"> <path id="ma" st ...

Is it possible to switch the background image when hovering?

Is the image proportion relevant to the issue at hand? <style> .img1:hover { background-image: url({%static 'images/img2.gif' %}); -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; backg ...

Gradient transition effect changing background color from bottom to top

I am facing an issue where I have a block and I want the background color to animate from bottom to top on hover. Can you please help me identify what is causing this problem? Your assistance is greatly appreciated. .right-block--wrapper { backgroun ...

How can I prevent users from selecting text when they right click using JavaScript?

My custom context menu on canvas works well, but I'm facing an issue with Text elements. When I try to right-click on a text element, it triggers text selection as if double-clicking. I attempted to use the following code: document.addEventListener(& ...

September always seems to throw my Date list off course, skipping a month and causing it to vanish without a trace

The issue at hand I have been working on developing an Open-Source Vue Application that features a Gantt Chart for visualizing tasks along a timeline. Users are able to customize the date range, with the default setting to display the current and upcoming ...

Reset input field value upon triggering a JavaScript alert

I am facing an issue with a dynamic field that receives its value from the database. I need to compare this value with an old value and trigger an alert if it is greater. In such cases, I want to reset the field back to an empty value. I am trying to achi ...

What steps should I take to troubleshoot and resolve a 500 internal server error in a Node.js/Express.js application?

Whenever I try to post data from an HTML form to my Express.js server, all I get is an Internal Server Error 500. It just displays POST /routeitisreaching 500 without any further explanation. I'm struggling to identify the root cause of this issue. E ...

Java - openpdf - Splitting words using hyphens

We are currently utilizing openpdf 1.3.26 template 2.1 to create PDFs from HTML and CSS. Within our coding, there is a div element styled as follows: .text-block{ display:block; text-align:justify; word-wrap: break-word; ...

Guidelines on retrieving an HTML element from a source document

To change a specific HTML section identified by a tag id in source code consisting of both HTML and PHP, I need to use PHP. If the code is purely HTML, a DOM parser can be utilized; otherwise, if there are multiple nested DIVs, regex with preg_match might ...