Developing a user-friendly widget for a website that is not optimized for mobile devices

Here's the backstory:

I'm currently in the process of creating a mobile-friendly widget for my clients. Unfortunately, they have web pages that are not optimized for mobile devices, and it doesn't seem like that will change anytime soon.

The Proposed Solution:

My initial idea was to take the widget out of the regular page flow by using position:fixed, adding a viewport meta tag, and voila! Everything should work smoothly...right? Check out this fiddle for reference.

The Issue at Hand:

However, the proposed solution seems to fail on certain mobile devices. My colleague experienced a situation where they could scroll away from the element marked as position:fixed on their Android 4 or 5 device (so it's not the older 2.1-2.3 bug). It appears that iPhones exhibit similar behavior.

Essentially, it behaves more like position:absolute positioned in the top-left corner of the page.

Further Details on the Proposed Solution:

I begin by injecting the viewport meta tag using JavaScript:

$('head').append('<meta name="viewport" content="width=device-width,initial-scale=1"/>');

Assume we have a simple HTML structure:

<html>
    ...
    <div class="overlay">
        <div class="modal">
            <div class="content">...</div>
        </div>
    </div>
    ...
</html>

and the accompanying CSS:

.hide-overflow {
    overflow: hidden;
}
.overlay {
    position: fixed;
    -webkit-backface-visibility:hidden; /* This may not be effective */
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: table;
    overflow: hidden;
    z-index: 1000;
}
.modal {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}
.content {
    display: inline-block;
    width: 800px;
    height: 500px;
}
@media (max-width: 800px) {
    .overlay * {
        max-width: 100%;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
    }
    .content {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
    }
}

Realizing that this might not suffice, I also included JavaScript to prevent scrolling on the <body> and outer-most <div>:

//This code is activated only when the widget is active and removed upon deactivation.
$('body').addClass('hide-overflow'); //Just sets overflow:hidden, in case you missed it ;)
$('body > div').addClass('hide-overflow');

On my Galaxy Note phone's default browser, everything works perfectly without any issues. However, it seems on iPhones, some Android devices, and so on, users can freely scroll away from the element styled with position:fixed as if it were set as position:absolute. How can I ensure that position:fixed actually works as intended?

Answer №1

The solution turned out to be more straightforward than expected. While using javascript, I was simply appending my hide-overflow class to the body and first div element. The original class code looked like this:

.hide-overflow {
    overflow: hidden;
}

The issue was resolved by making the following adjustments:

.hide-overflow {
    overflow: hidden;
    width: 100% !important;
    height: 100% !important;
    -webkit-box-sizing: border-box !important;
    -moz-box-sizing: border-box !important;
    box-sizing: border-box !important;
}

Simply add this modified class to the <body> tag when the widget is displayed, and remove it when the widget is hidden.

You can view the functioning fiddle here.

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

The fullscreen API allows for the creation of a full-screen element containing internal elements, while also enabling the functionality

Is it possible to utilize the fullscreen API to make any element fullscreen, even if it contains multiple internal elements, while still maintaining the functionality of dropdowns and other custom elements that may be located in different areas of the page ...

The submission of the form proceeds even with the warning displayed

I am facing an issue with a form that consists of one text field and a submit button. The user is required to input a 3-digit number, and if the number is greater than 200, a warning should be displayed. If the user clicks OK, the form should be submitted. ...

Generating duplicate uuidv4 key values within a Sequelize model

Hello, I'm new to TypeScript and Express. I've set up a UUID type attribute but it always returns the same value. 'use strict'; const { v4: uuidv4 } = require('uuid'); const { Model, Sequelize } = require('sequelize&apo ...

What specific CSS selector should be targeted in order to modify the appearance of this button?

I'm attempting to alter the appearance of a button within my Wordpress site, but I've hit a roadblock in identifying the correct element to modify. So far, I've tried targeting: .input#chained-quiz-action-1, however, the button stubbornly re ...

Website experiences technical difficulties but database remains up-to-date

I previously made a similar post, but I have not resolved the issue yet. Here is the output from my terminal: 23 Dec 22:31:23 - Serving request for url[GET] /team 23 Dec 22:31:23 - Successfully created team with Name : Japan 23 Dec 22:31:23 - Serving re ...

Font Awesome icons occasionally display as squares, but typically they render correctly

I've noticed a strange issue on my website where the font awesome icons sometimes display as squares instead of their intended design. After searching through forums, it seems that my situation is different from others experiencing similar problems. I ...

Oops! Remember to always `await server.start()` first before using `server.createHandler()` in next.js

An error is popping up when I attempt to check the functionality of Apollo GraphQL. Error: You must await server.start() before calling server.createHandler() Note: Although there is a similar question regarding this issue, it is specific to Express. Error ...

Enhance your webpage with a stunning background video

I'm trying to add a background video that covers the entire screen but maintains a height of 400px, similar to the one shown here. Is there a way to achieve this without using JavaScript? Below is the HTML code I currently have: <div class="pr ...

Adding Angular dependencies through Gulp (with the help of Browserify)

Exploring the use of Gulp and Browserify in my new Angular application. Inquiry: How can I effectively include angular dependencies in the app.js file without encountering dependency errors? Even with minimal dependencies, such as using only $stateProvid ...

Optimizing performance: Enhance readback operations in Canvas2D by enabling the willReadFrequently attribute for faster getImageData processing

I am currently utilizing the react-wordcloud package and encountering an issue where the word cloud adjusts to fit 70% of the screen size whenever the container size changes. My console is being flooded with this warning message: https://i.sstatic.net/vdV ...

Are the connections from a single array unique?

A generous user shared this code with me: $singles = valley_images(); $groups = valley_group_images(); $images = array_merge($singles, $groups); $sortArray = array(); foreach($images as $image){ foreach($image as $key=>$value){ if(!iss ...

Angular elements that function as self-validating form controls

I'm wondering if there's a more efficient approach to achieve this, as I believe there should be. Essentially, I have a component that I want to function as an independent form control. This control will always come with specific validation requi ...

Adding an object to an array using the Array.push() method deposits an array

Currently, I am extracting the days of absence of my colleague from excel files and storing them in a MongoDB database using Mongoose and Express.js. The process of reading the data is smooth; however, when trying to update the data in the database, an un ...

Retrieving the final item from an ng-repeat loop that has been sorted using the orderBy function

I need assistance in creating a list of terms and their definitions, each categorized under a header based on the first letter of the term. A Apple B Banana Currently, I am using the following code: <div ng-repeat="definition in definitions"& ...

How can I choose specific options by clicking based on the select name's value with web scraping?

I'm attempting to scrape the select dropdown menu below in order to retrieve its text content. Unfortunately, I can't rely on the name attribute as "P889O1" varies for each product from which I need to extract data. I considered using 'cont ...

Dynamically Remove One Form from a Django Formset

I have been using the following code to dynamically add a form to my formset: .html {{ form2.management_form }} <div id="form_set"> {% for form2 in form2.forms %} <table class="table table2" width=100%> ...

What is the best way to send an error message and corresponding HTTP status code to trigger the jQuery AJAX error function?

With the use of Spring framework, I have implemented a SimpleMappingExceptionResolver to handle unexpected exceptions in my application. The resolveException method catches these exceptions and returns an error message back to the HTTP client through a Mod ...

How can the jQuery click() method be utilized?

Currently working on a web scraping project, I have managed to gather some valuable data. However, I am now faced with the challenge of looping through multiple pages. Update: Using nodeJS for this project Knowing that there are 10 pages in total, I atte ...

What could be the reason for my CSS selector with :target not functioning properly?

I tried to implement the instructions I found online for using :target, but it's not working as expected. My goal is to change the background color and font color of #div1 when the first link is clicked, and to change the border of #div2 when the seco ...

retrieve the chosen option from the dropdown menu

Whenever I try to display the input type based on the selection from a select element, I encounter an issue Here is the select element within my view: <select id="type" name="type_id" class="form-control" required> @foreach($type as $row) & ...