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

When the object contains multiple arrays, filter out the id and remove it when clicked

I am working with an object that contains multiple arrays and aiming to filter out the id of the item to be removed onClick. However, I have encountered an error while trying to implement this logic. The error message I received is filter is not a functio ...

What is the best way to implement two for loops in a Django template to handle sending and receiving chat messages efficiently?

I am attempting to implement sending and receiving messages in a Django template using a for loop. Here is my views function: @login_required def message_form(request, id, slug, user_id): user2 = request.user user_id = user_id user = get_objec ...

Wrap every character in a span tag within this text

Extracting search strings from an object obj[item].coveredText and replacing each character with a span is what I aim to achieve. Currently, I can only replace the entire search string with a single span element. Any suggestions would be greatly appreciat ...

conducting thorough analysis for detecting modifications akin to $watchCollection in Angular2

I have a situation where I am passing an array of objects from my parent component to child components. Even when a new item is added to the array or the property of an existing object changes, it fails to trigger the ngOnChanges for the affected component ...

Ways to implement a delay in a function?

I'm looking for a way to introduce a delay in my function. Should I enclose the function within a delay function, or is there a different method to ensure that the animation doesn't trigger until 5 seconds after the page has loaded? var textTo ...

File uploading using JQuery and AJAX

An error occurred: Cannot read property 'length' of undefined I'm facing an issue with 3 file fields and their upload buttons. The problem lies in the fact that the file field is being returned as undefined. Here is the JavaScript code: $ ...

Is it possible to store an HTML element tag in a variable?

I've been learning JavaScript on w3schools and freecodecamp, but I stumbled upon something in w3schools that has me puzzled. Can someone please explain why this particular code snippet works? The variable "text" is declared as containing the string " ...

`When you extend a $resource object, it effectively removes the prototype from the

Here's the current code snippet I'm working with: // Factory angular.factory('Student', function() { var defaults = { StudentId: null }; var Student = function(params) { angular.extend(this, angular.copy(de ...

What might be causing the invisibility of a particular div element?

Here is the layout in the div element: <div class=" wrap clear"> <div class="block pink float"></div> <div class="block blue float"></div> <div class="block orange float"& ...

Make sure to include the environment variable in the package.json file before running Cypress in headless mode

I am trying to determine whether Cypress is running or not within a NextJS application. My goal is to prevent certain http requests in the NextJS application when Cypress tests are running. Currently, I am able to detect if Cypress is running by using the ...

What is the best way to execute a function based on the width of the screen?

Two functions need to be called based on the screen width. Here is one attempt: var winWidth = $(window).width(); var sections = function() { $('.image').each(function(){ var $this = $(this), x = $this.find('img'). ...

Adding an ellipsis (...) at the end of a specific number of characters within AngularJS

My current project involves extracting educational data from Facebook and displaying it on my webpage. However, I have run into an issue with strings that are too long. I am looking for a solution to truncate the string after a certain number of characters ...

Help me figure out how to independently toggle submenus on my navbar by utilizing the Vue.js composition API

I am currently working on developing a navbar using the Vue.js composition API. My primary objective is to toggle the submenus when a user clicks on them. However, since I am iterating through an object to display the submenus, I am faced with the challeng ...

Utilize Bootstrap4 to position content above the navigation icon

I need assistance to modify my code so that it will have the following appearance: I successfully created a navigation bar icon and inserted the logo, but I am struggling to position the data above the navigation icon: My current code: <nav class="n ...

Having trouble grasping this concept in Typescript? Simply use `{onNext}` to call `this._subscribe` method

After reading an article about observables, I came across some code that puzzled me. I am struggling to comprehend the following lines -> return this._subscribe({ onNext: onNext, onError: onError || (() => {}), ...

invoking a method of the grandparent from within the grandchild component

My components are nested three levels deep: <GrandParent /> <Parent /> <Child /> In the Child component, I have a button that, when double clicked, should call a function in the GrandParent component. <button @dblclick=&quo ...

JavaScript scripts are unable to function within an Angular directive's template due to compatibility issues

I'm facing an issue with a directive (function (angular) { 'use strict'; function digest(factory) { var directive = { restrict: 'E', templateUrl: '/js/app/digest/templates/digest.tem ...

Can you explain why this unexpected bootstrap positioning is happening?

On my website, I have two large buttons (btn-lg) - one is placed at the top of the page with a hidden form beneath it (initially set to display: none), and the other button is below that with another hidden form. When clicked, the buttons reveal their resp ...

Reducer is not a standalone function in the realm of React Native's Redux framework

I need to implement a reducer in my react native application. The store constant is defined as follows: export const USER_PROFILE = 'USER_PROFILE'; This is the content of action.js file: import {USER_PROFILE} from '../constants/index'; ...

Is it possible for asynchronous functions to write to the same object concurrently and result in invalid values?

I have been experimenting with the code below to see if it can cause any issues with the integer i in the object context. My tests so far have not revealed any problems. // Node.js (v10.19.0) const Promise = require('promise') // object access ...