做了一个html5页面,页面初始化时,可以跟随浏览器的大小改变而改变尺寸页面字体大小。缩放代码如下:
scaleW = window.innerWidth / 320; scaleH = window.innerHeight / 480; var resizes = document.querySelectorAll('.resize'); for (var j = 0; j < resizes.length; j++) { resizes[j].style.width = parseInt(resizes[j].style.width) * scaleW + 'px'; resizes[j].style.height = parseInt(resizes[j].style.height) * scaleH + 'px'; resizes[j].style.top = parseInt(resizes[j].style.top) * scaleH + 'px'; resizes[j].style.left = parseInt(resizes[j].style.left) * scaleW + 'px'; } var scales = document.querySelectorAll('.txt'); for (var i = 0; i < scales.length; i++) { ss = scales[i].style; var stylestr = 'translateX(' + scales[i].offsetWidth * (scaleW - 1) / 2 + 'px) translateY(' + scales[i].offsetHeight * (scaleH - 1) / 2 + 'px)scaleX(' + scaleW + ') scaleY(' + scaleH + ') '; ss.webkitTransform = ss.MsTransform = ss.msTransform = ss.MozTransform = ss.OTransform = ss.transform = stylestr; }
试了几个手机浏览页面,没问题。但是用iphone5浏览时,页面元素缩放了,但是页面字体没有缩放。
与手机本身无关吧,你的iphone5 上的系统是哪个版本(ios 几)