Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize page adaptation by JavaScript

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

The knowledge of this article "JavaScript how to achieve page adaptation" is not understood by most people, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "JavaScript how to achieve page adaptation" article.

The principle of implementation:

Gets the width and height of the IE display screen. Determine which objects are fixed in absolute position, which are not fixed, and which length and width are fixed, and then, like the WIN FORM program, the size of the software interface, the length and width of the design-related objects, the absolute position and other attributes, but on WEB the program has no way to detect the change of window size in real time, so it can only use the method to realize self-adaptation to call recursively through the SetTimeout function.

The following is an excerpt from the SysForm.aspx implementation of the iSunXoft Hr open source project.

Var h; var w; function resize () {var he = document.body.offsetHeight; var wi = document.body.offsetWidth If ($("DataTable"). Style.display.toLowerCase () = = "| | $(" DataTable "). Style.display.toLowerCase () = =" inline ") {if (h==he&&w==wi) {if ($(" leftMenu "). Style.display.toLowerCase () = =" none ") {$(" DivDataList "). Style.width = wi-30;} else {$(" DivDataList "). Style.width = wi-223 } setTimeout ("resize ()", 1000); return;} h = he; w = wi; if (he > 100) {$("DivDataList"). Style.height = he-172;} if (wi > 200) {$("DivDataList"). Style.width = wi-223 If ($("leftMenu") .style.display.toLowerCase () = = "none") {$("DivDataList") .style.width = wi-30 } if ($("DataEmpWidows"). Style.display.toLowerCase () = = "inline" | | $("DataEmpWidows"). Style.display.toLowerCase () = "") {if (h==he&&w==wi) {if ($("leftMenu"). Style.display.toLowerCase () = = "none") {$("DataEmpWidows"). Style.width = wi-30 } else {$("DataEmpWidows"). Style.width = wi-223;} h = he; w = wi; if (he > 150) {$("DataEmpWidows"). Style.height = he-132;} if (wi > 200) {$("DataEmpWidows"). Style.width = wi-223 If ($("leftMenu") .style.display.toLowerCase () = = "none") {$("DataEmpWidows") .style.width = wi-30 } if (typeof ($("EipWindows"))! = "undefined") {/ / if ($("EipWindows"). Style.display.toLowerCase () = = "inline") / / {/ / if (h==he&&w==wi) / / {/ / if ($("leftMenu"). Style.display.toLowerCase () = = "none") / / {/ / $( "EipWindows") .style.width = wi-30 / /} / / else / / {/ / $("EipWindows"). Style.width = wi-223; / /} / /} / / h = he; / / w = wi; / / if (he > 150) / / {/ / $("EipWindows"). Style.height = he-132 / /} / / if (wi > 200) / {/ / $("EipWindows"). Style.width = wi-223; / / if ($("leftMenu"). Style.display.toLowerCase () = = "none") / / {/ / $("EipWindows"). Style.width = wi-30; / /} / /} /} setTimeout ("resize ()", 1000) } resize ()

Note: $("") is a changing element.

Then call resize () on the web page; once there is a change in window size or resolution, it can ensure that real adaptation can be achieved.

The above is about the content of this article on "how to achieve page adaptation in JavaScript". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report