Remember the problem of getting page width and height due to web page zooming in web project development

problem:

Today, when I found a template for the login interface on the Internet and was going to apply it to the login interface in my project, I found that the width and height of the canvas label are not the width and height of the web page, but the original template of the web page is normally filled. Page. After searching the information, I finally learned that the original problem is the zoom ratio. Because I added a CSS style for the 125% zoom to 80% in the web project, and then calculate the width and height of the canvas in the js of the template, it is calculated error.

Solution:

Calculate the width and height in js by multiplying a scaling factor window.devicePixelRatio .
Insert picture description here

Published 111 original articles · won praise 2 · Views 3533

Guess you like

Origin blog.csdn.net/m0_38088647/article/details/103583338