<script>/** * MobileWeb General function Helper, including commonly used UA judgment, page adaptation, search parameter to key value pairs. * This JS should be introduced as early in the head as possible, reducing repainting. * * The Fixscreen method is adapted according to two conditions, and the method is executed automatically. * 1. Fixed width: Corresponding meta tag notation--<meta name= "viewport" content= "width=750" > * This method extracts the width value and actively adds the scale related attribute value. * Note: If Initial-scale is specified in the META tag, the method will not be processed (i.e. not executed). * 2. REM: Do not write meta tags, the method is automatically generated according to DPR, and in the HTML tag add DATA-DPR and font-size two attribute values. * This method constraint: IOS system Maximum DPR = 3, other system DPR = 1, the maximum width per DPR page (that is, page width/dpr) = 750,rem conversion ratio is 16. * Corresponding to the development of CSS, any elastic size using REM units, the REM default width is the width of the visual version/16; * Scss $ppr (pixel per rem) variable notation-$ppr: 750px/16/1rem; * Element size notation--html {font-size: $PPR *1rem;} body {width:750px/$ppr;}. */Window.mobileutil = (function (win, doc) {var UA = navigator.useragent, isandroid =/android| Adr/gi.test (UA), Isios =/iphone|ipod|ipad/gi.test (UA)&&!isandroid,//The UA of some domestic machines is said to contain both Android iphone characters ismobile = Isandroid | | Isios; Rough judgment return {isandroid:isandroid, Isios:isios, Ismobile:is Mobile, Isnewsapp:/newsapp\/[\d\.] +/gi.test (UA), Isweixin:/micromessenger/gi.test (UA), isqq:/qq\/\d/gi.test (UA), Isyixin:/yixin/gi.test (UA), Isweibo:/weibo/gi.test (UA), Istxweibo:/T (?: x|encent) Micro Blog/gi.test (UA), Tapevent:ismobile? ' Tap ': ' click ',/** * Zoom page */fixscreen:function () { var Metael = doc.queryselector (' meta[name= "viewport"] "), METACTT = Metael? Metael.content: ", Matchscale = Metactt.match (/initial\-scale= ([\d\.] +)/), MatchWidth = Metactt.match (/width= ([^,\s]+)/); if (!metael) {//REM var docel = doc.documentelement, maxwidth = DOCEL.DATASET.MW | | 750,//MAX page width per DPR DPR = Isios? Math.min (Win.devicepixelratio, 3): 1, scale = 1/DPR, Tid; Docel.removeattribute (' DATA-MW '); DOCEL.DATASET.DPR = DPR; Metael = doc.createelement (' meta '); Metael.name = ' viewport '; Metael.content = Fillscale (scale); DocEl.firstElementChild.appendChild (Metael); var refreshrem = function () {var width = Docel.getboundingclientrect (). width; if (Width/dpr > maxwidth) {width = maxwidth * DPR; } var rem = width/16; docEl.style.fontSize = rem + ' px '; }; Win.addeventlistener (' Resize ', function () {cleartimeout (TID); Tid = SetTimeout (Refreshrem, 300); }, False); Win.addeventlistener (' Pageshow ', function (e) {if (e.persisted) { Cleartimeout (TID); Tid = SetTimeout (Refreshrem, 300); }}, False); Refreshrem (); } else if (IsMobile &&!matchscale && (matchwidth && matchwidth[1]! = ' device-width ')) {//Fixed width var width = parseint (matchwidth[1]), IW = Win.innerwidth | | width, ow = Win.outerwidth | | IW, sw = Win.screen.width | | IW, saw = Win.screen.availWidth | | IW, ih = Win.innerheight | | Width Oh = Win.outerheight | | IH, ish = Win.screen.height | | IH, Sah = Win.screen.availHeight | | IH, W = math.min (IW, OW, SW, saw, IH, oh, ish, sah), scale = w/width; if (Scale < 1) {metael.content = Metactt + ', ' + fillscale (scale); }} function Fillscale (scale) {return ' initial-s Cale= ' + scale + ', maximum-scale= ' + scale + ', minimum-scale= ' + scale + ', user-scalable=no '; }},/** * turn href parameter into key value pair * @param href {string} specified href, default to current page hr EF * @returns {object} key value pair */getsearch:function (HREF) { href = href | | Win.location.search; var data = {}, Reg = new RegExp ("([^?=&]+) (= ([^&]*)]?", "G"); href && href.replace (reg, function ($ $, $ $, $ $) {Data[$1] = $ $; }); return data; } }; }) (window, document); Default direct Adaptation page Mobileutil.fixscreen (); </script>
Adaptive phone page size prohibit zooming