How can we prevent the modal from extending beyond the boundaries of the phone screen when zoomed in

I am currently developing a web application that features a large content page, specifically a map which should display detailed information upon zooming in similar to Google Maps. The interactive elements on my map are clickable, triggering a modal popup with details about the location. However, I am facing an issue where the modal is also zoomed out to fit the outer div containing the expansive map.

While it's intentional for the map to exceed the phone screen upon zoom, the problem arises when the modal appears extremely large, requiring users to constantly zoom out to view it and then zoom back in to locate their desired place on the map.

Is there a solution to ensure that the modal is sized to the screen rather than the outer div?

Additional information: My web app utilizes AngularJS, and the modal is implemented using uibmodal from ui-bootstrap.

The map is within a div inside an Angular view, set to 100% width, with the height forced to be width*1.45 following the map's ratio format. This adjustment is done through an Angular directive that dynamically sets the height based on the screen resize event.

If my explanation is unclear, you can visit the live demo at . On PC browsers, zooming is disabled, but if accessed via a mobile device and zoomed in while clicking on a location, the issue with the oversized modal becomes evident.

This particular problem has been challenging to search for solutions online. Any suggestions are greatly appreciated!

Here's how the modal is triggered in the HTML page:

<span ng-click="showDialog(shop)" class="shop">{{shop.name}}</span>

And here's how it is invoked within Angular:

.controller('ShopCtrl', function ($scope, $location, $uibModal, ShopService, selectedShopFac) {
        $scope.shops = [];
        $scope.selectedShop = selectedShopFac.setSelectedShop({});
        ShopService.getShops().then(
                function (response) {
                    $scope.shops = response.data;
                },
                function (response) {
                    console.log(response.data.toString());
                });
        $scope.showDialog = function (shop) {
            $scope.selectedShop = selectedShopFac.setSelectedShop(shop);
            $uibModal.open({
                templateUrl: 'app/home/shop/shop.html',
                scope: $scope
            });
        };
    })

Lastly, here's the directive responsible for managing the size of "the map," the parent div to the shops:

.directive('mapDir', function ($window) {
        return {
            restrict: 'A',
            link: function (scope, element) {

                var mapDiv = element;

                angular.element(document).ready(function () {
                    mapDiv.height(mapDiv.width() * 1.45);

                });

                function onResize() {
                    mapDiv.height(mapDiv.width() * 1.45);
                }

                onResize();
                angular.element($window).on('resize', onResize);
            }
        };

    })

Answer №1

After some experimenting, I came up with a workaround for this issue.

In the shop.html file, I made the following addition at the top:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes" />

By setting maximum-scale=1.0, the screen reverts to its unzoomed state, allowing the modal to fit perfectly on the screen. However, this also resulted in the map being zoomed out, which was not ideal.

To address this, I added a .closed.then function in the controller to reset the metatag and enable zooming back in on the map. Here's how it looks:

$scope.showDialog = function (shop) {
            $scope.selectedShop = selectedShopFac.setSelectedShop(shop);
            $uibModal.open({
                templateUrl: 'app/home/shop/shop.html',
                scope: $scope
            })
            .closed.then(function () {
                $window.document.getElementsByName('viewport')[0].content = "width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=yes";
            });
        };

When I tested this on my phone using Chrome on Android, it worked perfectly. However, I encountered compatibility issues on my iPad due to outdated versions of Chrome and Safari.

While this solution may not be foolproof, it serves as a practical workaround that gets the job done effectively.

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

How come the h2::after element is positioned directly beneath the main h2 element, and with a margin-bottom?

I'm puzzled as to why the margin-bottom property in the main h2 element isn't affecting its "::after" element. Both are defined as block elements, so one margin should provide enough space between them. Even though the "h2::after" element has 0 m ...

The hover effect flickers in Firefox, but remains stable in Google Chrome

Here is an example link to check out: I am facing a dilemma on how to solve this issue and unsure if it is related to jQuery or the DOM structure. If you have any suggestions, they would be greatly appreciated. Thank you! ...

Subclass Pseudoclass in JavaFX is a powerful feature that

I wanted to create two different styles of buttons in one css file. To achieve this, I added a class to the second button using: close.getStyleClass().add("close-button"); Now, I can reference this button in the css by: .button.close-button However, I ...

An error was encountered regarding an undefined property while executing NPM and PACT

I'm currently working on implementing the PACT workshop example with some different data. Although this might be more of a Javascript/Node query, I am a bit stuck as a beginner. Here is a snippet from the consumer.spec.js file: const chai = require ...

Try using the slice method to cut a portion of a JSON object

I am trying to chop up a JSON array, but keep encountering the error message below: Object # has no method 'slice' This is my current code snippet: $scope.getPagedDataAsync = function (pageSize, page, searchText) { setTimeout(function ( ...

Explore the various timer functionalities available in Angular.js

I am working on a project that requires displaying two timers on a webpage, each with different start times. The first timer should only show for 5 seconds, and then after 10 seconds, the second timer should be displayed. I am new to Angular and have writ ...

Using single quotation marks within a string can cause issues in javascript

I am curious about how to handle single quote marks and other symbols within user-generated text without causing issues with the JavaScript code. Currently, if a user enters a title like "I wouldn't", it breaks the JavaScript functionality. <a cl ...

How can I resolve the issue with the HTML/CSS footer not functioning properly on Safari for iPhone in my mobile site?

Struggling with a mobile website issue here. The client wants text-based buttons/links at the bottom, so I added them in, but my skills with size percentages are a bit rusty. I need these buttons to line up horizontally and adjust their width accordingly ...

Adding controllers dynamically to ng-includes allows for more flexibility and customization in

How can I dynamically change the controller for ng-include in AngularJS? In my application, users can create content pages along with controllers. I am able to adjust the ng-include source dynamically, but I am unsure of how to associate a new controller ...

Is it possible to access the passed arguments in the test description using jest-each?

Utilizing TypeScript and Jest, consider this sample test which can be found at https://jestjs.io/docs/api#testeachtablename-fn-timeout it.each([ { numbers: [1, 2, 3] }, { numbers: [4, 5, 6] } ])('Test case %#: Amount is $numbers.length =&g ...

Building module dependencies in the Dojo dojo

I'm in the process of utilizing the Dojo builder to compile a unified file that encompasses all the necessary modules for my application, excluding the application itself. Below is an illustration of a layer definition: layers: { 'dojo/dojo ...

Ways to retrieve the output from an AJAX call

Today I'm developing a JavaScript function named "sendData". This function simplifies the process by eliminating the need to manually code an entire ajax statement. However, considering that it operates asynchronously, I found myself wondering how to ...

Using Node.js and Express to import a simple JavaScript file as a router

Can anyone help me understand how to import the user.json json file into my user.js? I want the json file to be displayed when typing /user but I'm struggling with the new version of Node. index.js import express from 'express'; import body ...

AngularJS's $http.get function has the ability to read text files, but it struggles with reading JSON

I'm new to angularjs and I am struggling to retrieve data from a json file using the $http.get method. It seems to work fine when I try to read a simple txt file, but not with the json file. I can't seem to pinpoint where the issue lies... Belo ...

What is the method for closing an <iframe> element directly?

A web page called room.html contains a table with an onclick function named place(): function place() var x = document.createElement("IFRAME"); x.setAttribute("src", "loading.html"); document.body.appendChild(x); } What is ...

I am facing difficulties in installing the necessary node modules for my Angular project

After attempting to run npm install, an error message is displayed towards the end: error syscall unlink 22396 error The operation was rejected by your operating system. 22396 error It's possible that the file was already in use (by a text editor or ...

Ensure that the dropdown menu remains visible even after the mouse no longer hovers over it

Looking to create a main menu with dropdown items that appear when the user hovers over them? You may have noticed that typically, the dropdown disappears once the hover event is lost. But what if you want the menu to stay visible and only disappear upon c ...

The arrangement of pictures on a card

I decided to tweak the original concept by placing the images inside a Bootstrap card. However, the end result is that the images appear to be floating. https://i.stack.imgur.com/Uf721.png Any suggestions on how to make them fit nicely within the card? ...

CSS - Ignoring Padding Causes Unexpected White Space to Appear

I am encountering a simple error, and the following address will direct you to where the issue can be seen. Why is certain parts of the header appearing white instead of the light shade of green it is set to be? It should be positioned right at the top un ...

What is the process of acquiring JSON and converting it into a JavaScript object array?

Can someone please assist me in converting the JSON generated in Spring Boot into a JavaScript object array? I'm currently facing some difficulties. https://i.stack.imgur.com/Tx5Ri.png I've been using XMLHttpRequest and my JS code is as follows ...