Common JS sharing on the mobile side
1. Divide the cell phone screen by 10 points (which I use in this form) and use REM to calculate what needs to be adaptive.
<Scripttype= "Text/javascript"> (function(Doc, win) {varDocel=doc.documentelement, Resizeevt= 'Orientationchange' inchwindow? 'Orientationchange' : 'Resize', Recalc= function () { varclientwidth=Docel.clientwidth; if(clientwidth> 640) {clientwidth= 640; } docEl.style.fontSize=(clientwidth/ Ten) + 'px'; }; if (!Doc.addeventlistener)return; Win.addeventlistener (Resizeevt, Recalc,false); Doc.addeventlistener ('domcontentloaded', Recalc,false);}) (document, window);</Script>
2. Determine whether the mobile phone screen
Judging the phone screen status: Window.addeventlistener ("Onorientationchange" in window? "Orientationchange": "Resize", function () { if (window.orientation = = = | | window.orientation = = 0) { alert (' Vertical screen Status! '); } if (window.orientation = = = | | window.orientation = = -90) { alert (' Horizontal screen state! '); } }, False); Mobile browser generally support window.orientation This parameter, through this parameter can determine whether the phone is in a horizontal screen or vertical screen state.
Mobile initialization of common JavaScript code