Testing the screen size automatically using Javascript

Hello everyone, I've implemented a JavaScript code that triggers an image to slowly appear and darken the background when a link is clicked. However, on an iPad, the background doesn't completely turn black as intended. The CSS specifies that the background should cover 100% of the screen. Here's the relevant part of the CSS:

  #backgroundPopup{  
  display:none;  
  position:fixed;  
  _position:absolute; /* hack for internet explorer 6*/  
  width:100%;  
  height:100%;  
  top:0;  
  left:0;  
  background:#000000;  
  border:1px solid #cecece;  
  z-index:5;  
  }

Upon debugging, I noticed that the screen size is only detected initially when the browser loads. In the case of iPads, the screen may be zoomed in or orientation changed leading to some white spots showing up. Is there a way to continuously track screen size changes using JavaScript? Any suggestions?

Answer №1

Whenever the width of the viewport is altered, the window.onresize event is triggered. Capture this event and adjust the size of the black element accordingly.

Answer №2

Using percentages for width and height can sometimes be difficult. In this situation, one alternative is to set the dimensions to a specific number of pixels that correspond to 100% of the width and height (using JavaScript/jQuery) instead of using percentages.

I hope this suggestion proves to be helpful!

Update:

By utilizing this script, you can obtain the size of the browser window (not the screen resolution, only the useful size). This information could be exactly what you need in order to accurately adjust the height and width of your background popup through JavaScript.

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

transition effect of appearing and disappearing div

Having trouble creating a fade out followed by a fade in effect on a div element. The fade out happens too quickly and the fade in interrupts it abruptly. Here is the JavaScript code: $('#fillBg').stop(true,false).fadeTo(3000, 0); $("#fillBg"). ...

Guide on implementing CSS3 parser with HtmlUnitDriver

As an example, let's consider a scenario where we have a selector to target the active menu item: $("ul#menu li a[href='/']") And a selector to target the remaining menu items (1): $("ul#menu li a:not([href='/'])") However, the ...

What are some ways to implement webkit-line-clamp on a website?

I'm trying to shorten my paragraph using the following CSS code: white-space: nowrap; overflow: hidden; text-overflow: ellipsis; However, the issue is that it condenses everything into one line. I actually want the text to display on 3 lines before t ...

The homepage is not converting to a different language

Using the WPML plug-in for my WordPress website has been successful in translating most of my pages, but I am running into an issue with the home page. Even though I have manually translated and published the home page, it still does not translate when cli ...

JavaScript: Creating a new entry in a key-value paired array

I am in the process of creating a dynamic menu for use with jQuery contextMenu. I have encountered an issue when trying to add a new element, as it keeps showing the error message 'undefined is not a function'. The menu functions correctly witho ...

"Fill the designated area on the webpage with data retrieved from an external script

In my current project, I am utilizing Angular and JQuery to enhance re-usability by setting the header and footer as partials. However, I encountered an issue where I needed certain javascript functions to be executed within the footer upon loading - a tas ...

What could be the reason behind React's decision to not convert JSX to an HTML component and instead return [object Object]?

Please locate the specified console log within the code snippet provided below. This particular console log outputs a string value, indicating that an object is not being passed in this instance. However, despite this, React fails to recognize the JSX an ...

Include token in src tag requests Angular version 8

In the process of developing a website, I have encountered a challenge. I am creating a platform where users can access another website I am currently working on after they log in. Once authorized, users receive a JWT token which is sent in the header with ...

"Patience is key when it comes to waiting for an HTTP response

Looking for a solution in AngularJS, I have a service that calls the backend to get some data. Here is how the service looks: app.factory('myService', ['$http', '$window', '$rootScope', function ($http, $window, $ro ...

Performing bulk operations on all selected rows in a table using Angular 6

Within my Angular 6 web application, there is a table with checkboxes in each row. My goal is to be able to perform bulk actions on the selected rows, such as deleting them. One approach I considered was adding an isSelected boolean property to the data m ...

Designing a webpage layout with DIV elements that span across multiple rows

I am attempting to create a layout that features two columns, with the right column spanning two rows. I am looking to accomplish this using only DIV tags: +-----------+-----------+ + + + + + + +-----------+ ...

"Collaborative Drive" assistance within Google Apps Script

Currently, I am developing a JavaScript tool within Google Apps Script to analyze various document properties such as the validity of links and correct permissions settings. To achieve this, I have been utilizing the API outlined in https://developers.goog ...

Leveraging v-for within a component that incorporates the <slot/> element to generate a versatile and interactive Tab menu

Currently, I am in the process of developing a dynamic tab menu using Vue 3 and slots. Successfully implementing tabs, I have created BaseTabsWrapper and BaseTab components. The challenge lies in using v-for with the BaseTab component inside a BaseTabsWrap ...

What is the best way to dynamically insert a new row into a table, with each row containing a table heading and column?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="tbl" class="tbl1"> <tr> <th> mobileno </th> <td class='mo' id="mo_0"> </td> ...

Is the term 'Literal' in Javascript Arrays simply referring to its dynamic nature, allowing it to be modified at any time?

I'm confused why Mozilla refers to this as an Array 'Literal' when it's declared using the VARIABLE keyword and its content can be modified... var drinks = ["Espresso", "Latte", "Cappuccino"]; Could someone shed some light on this for ...

What causes the failure of data reaching the server?

I need to make updates to some details in a few tables, but I'm having trouble getting it to work. Can someone help me figure out what's wrong? <body> <form class="" action="view_update_emp.php" method="post& ...

Exploring the concept of inheritance and nested views within AngularJS

I've encountered a challenge while setting up nested views in AngularJS. Utilizing the ui-router library has been beneficial, but I'm facing issues with separate controllers for each view without proper inheritance between them. This results in h ...

What is the best approach to integrating an idle timeout feature with identityserver4 and aspnet identity for a secure implementation?

Currently, I am developing a login site using IdentityServer4 (server UI) with .NET Identity in .NET Core 2.2 Razor Pages. I have implemented a javascript modal alert that notifies users of an impending idle timeout and redirects them to the logout screen ...

A Nuxt plugin that integrates a separate website into the serverMiddleware

The concept Imagine having a main Nuxt website just like any other. Now, think about adding my module to your project. This module will then introduce a subdomain "admin.example.com" to your project, creating a fully functional Nuxt-based website that ope ...

Where can I locate a specific child element in this scenario?

Currently, I am exploring the possibilities of integrating AngularJS into my application and have encountered a question regarding the click event implementation. Within my HTML code: <div ng-click='clickMe()' ng-controller='testCtrl&ap ...