简体   繁体   English

如何在页面加载之前获取此脚本触发器

[英]How to get this script trigger before the page loads

I want this script to be executed before the page is shown to the user so that the user does not see the page to be adjusted in real time.我希望在向用户显示页面之前执行此脚本,以便用户看不到要实时调整的页面。

Can anyone help?任何人都可以帮忙吗?

<script>
        $(document).ready(function () {
            onResize();
            $(window).resize(function () {
                onResize();
            });
        });
        function onResize() {
            var w = $(window).width();
            var ratio = 1;
            if (w < 1920) {
                ratio = (w / 1920);
            }
            if (isTablet()) {
                ratio = ratio * 1.25;
            }
            if (isMobile()) {
                ratio = ratio * 3;
            }

            $('body').css('font-size', ratio + 'px');
        }

        function isTablet() {
            if ($('.tablet:visible').length > 0) {
                return true;
            } else {
                return false;
            }
        }
        function isMobile() {
            if ($('.mobile:visible').length > 0) {
                return true;
            } else {
                return false;
            }
        }
</script>

what you're trying to do with Javascript could be easily done with css only and the usage of media queries .您尝试用 Javascript 做的事情可以很容易地用 css 和媒体查询的使用来完成。 I would suggest you to learn about them instead of using "hacks" to do something that is not the regular behaviour of a web page我建议您了解它们,而不是使用“黑客”来做一些不是 web 页面的常规行为的事情

Use CSS to hide page content, and then execute this code, and then display page content.使用CSS隐藏页面内容,然后执行这段代码,然后显示页面内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM