最近做了两个关于h5页面对接公众号的项目,不得不提打开微信浏览器内置地图导航的功能确实有点恶心。下次想起来了的话,进行总结分享一下如何处理。在vue移动端h5页面当中,其中适配是经常会遇到的问题,这块主要有死个方法可以适用。
方法一:引入淘宝开源的可伸缩布局方案
引入淘宝开源的可伸缩布局方案:https://github.com/amfe/lib-flexible(此处可点击)
淘宝的其实也和viewport的有点像,但是它主要是根据设备设备像素比设置scale的值,保持视口device-width始终等于设备物理像素,屏幕大小动态计算根字体大小,具体是将屏幕划分为10等分。这块也可以直接用js实现,后面会提到
具体引入和使用方法,移步github查看,非常详细。
方法二:viewport 的使用
github里边,有提到 viewport 的使用。我感觉这篇文章关于viewport 的介绍特别详细,包括比例、是否缩放等的属性介绍特别的详细,虽然文章的内容一大片的字看起来很多,但是请耐心看完,都是干货能很好的让你认识viewport。如果比较着急,请继续往下看总结图吧
https:///open/js/jweixin-1.0.0.js"></script> </head> <body> <div id="app"></div> <!-- 在iphone 5 中1rem=16px; html font-size =16px=1rem; --> <script> //得到手机屏幕的宽度 let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth; console.log('htmlWidth',htmlWidth) //得到html的Dom元素 let htmlDom = document.getElementsByTagName('html')[0]; // if(htmlWidth>640){//超过640大小的,字体根部都是16px // htmlWidth=640; // console.log('htmlWidth-true',htmlWidth) // } //设置根元素字体大小 htmlDom.style.fontSize = htmlWidth / 40 + 'px'; </script> </body></html>
方法四:根据css的媒体查询动态设置根部html字体大小
html {font-size: 625%; }@media screen and (min-width:360px) and (max-width:374px) and (orientation:portrait) { html { font-size: 703%; }}@media screen and (min-width:375px) and (max-width:383px) and (orientation:portrait) { html { font-size: 732.4%; }}@media screen and (min-width:384px) and (max-width:399px) and (orientation:portrait) { html { font-size: 750%; }}@media screen and (min-width:400px) and (max-width:413px) and (orientation:portrait) { html { font-size: 781.25%; }}@media screen and (min-width:414px) and (max-width:431px) and (orientation:portrait){ html { font-size: 808.6%; }}@media screen and (min-width:432px) and (max-width:479px) and (orientation:portrait){ html { font-size: 843.75%; }}总结
以上所述是小编给大家介绍的vue移动端html5页面根据屏幕适配的四种解决方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!