/* * @Author: mycm * @Email: afeizt@163.com * @QQ: 57725649 * @Date: 2022-04-26 * @LastEditors: mycm * @Description: file content */ ( function ( doc, win ) { // 监听 orientation changes var angle, dir; if ( "orientation" in screen ) { angle == screen.orientation.angle; } else if ( "orientation" in window ) { angle = window.orientation.angle; } else { angle = 0; } dir = 0 window.addEventListener( "orientationchange", function ( event ) { // 根据event.orientation|screen.orientation.angle等于0|180、90|-90度来判断横竖屏 //alert( screen.orientation.angle ); if ( dir == 90 || dir == -90 ) { dir = 1; } }, false ); var docEl = doc.documentElement;//documentElement 属性是根节点 resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'; recalc = function () { var body = document.getElementsByTagName( 'body' )[ 0 ]; var bodyClass = body.className; var designWidth = 1903; if ( bodyClass.indexOf( "mobile" ) !== -1 ) { if ( dir == 0 ) { designWidth = 350; } else { designWidth = 1903; } } else { designWidth = 1903; } var clientWidth = docEl.clientWidth; if ( !clientWidth ) return; // console.log( clientWidth, designWidth ) docEl.style.fontSize = 16 * ( clientWidth / designWidth ) + 'px';//设置html根元素的font-size if ( 16 * ( clientWidth / designWidth ) < 10 ) { // body.style.fontSize = '16px' // docEl.style.fontSize = '8px';//设置html根元素的font-size } else { } }; if ( !doc.addEventListener ) return; win.addEventListener( resizeEvt, recalc, true ); doc.addEventListener( 'DOMContentLoaded', recalc, false ); } )( document, window );