齐刘海适配

作者: 代艳霞 | 来源:发表于2020-04-30 17:59 被阅读0次
    <script>
                //需要插入在<head>标签内在所有脚本之前执行
                (function(win) {
                    if (!win.addEventListener) return;
                    var html = document.documentElement;
    
                    function setFont() {
                        function setRem() {
                            var cliWidth = html.clientWidth;
                            var w = document.documentElement.clientWidth,
                                h = document.documentElement.clientHeight;
                            var val = 750;
                            switch (window.orientation) {
                                case 0:
                                    //刘海在上边
                                    // displayStr = "direction_por";
                                    break;
                                case -90:
                                    //刘海在右边
                                    // displayStr = "direction_land_ops";
                                    val = 1334;
                                    break;
                                case 90:
                                    //刘海在左边
                                    // displayStr = "direction_land";
                                    val = 1334;
                                    break;
                                case 180:
                                    //刘海在下边
                                    // displayStr = "direction_por_ops";
                                    break;
                                default:
                                    if (w > h) {
                                        val = 1334;
                                    }
                            }
                            html.style.fontSize = 100 * (cliWidth / val) + 'px';
                        }
                        setRem();
                        setTimeout(function() {
                            setRem();
                        }, 300);
                    }
                    win.addEventListener('resize', setFont, false);
                    setFont();
                })(window);
            </script>
    

    相关文章

      网友评论

        本文标题:齐刘海适配

        本文链接:https://www.haomeiwen.com/subject/rugcmhtx.html