简体   繁体   English

如何将两个JavaScript合并为一个

[英]How to merge two JavaScripts as one

I have these two JavaScripts. 我有这两个JavaScript。 One is for the preloader and the other ones are for mail chimp subscribe form. 一个用于预加载程序,另一个用于邮件黑猩猩订阅表单。 In my MailChimp account, I've set the form to appear after 20seconds but my problem is, it loads faster than my webpage and sometimes it would appear before my preloader is gone. 在我的MailChimp帐户中,我将表单设置为在20秒后显示,但是我的问题是,它的加载速度比网页快,有时它会在预加载器消失之前出现。 It's really not what I want. 真的不是我想要的。 Please is it possible to have the mailchimp show only when the entire page is done loading? 请问是否只有在整个页面加载完成后才显示mailchimp? I'm still new to JavaScript and jquery and I have no idea on how to do this. 我还是JavaScript和jquery的新手,我也不知道如何执行此操作。 Please help. 请帮忙。 Below are the scripts. 以下是脚本。 Thanks for helping. 感谢您的帮助。

<script type="text/javascript">
var clPreloader = function() {

        $("html").addClass('cl-preload');

        $WIN.on('load', function() {

            //force page scroll position to top at page refresh
            // $('html, body').animate({ scrollTop: 0 }, 'normal');

            // will first fade out the loading animation 
            $("#loader").fadeOut("slow", function() {
                // will fade out the whole DIV that covers the website.
                $("#preloader").delay(300).fadeOut("slow");
            }); 

            // for hero content animations 
            $("html").removeClass('cl-preload');
            $("html").addClass('cl-loaded');

        });
    };
</script>
<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>

<script type="text/javascript">window.dojoRequire(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us19.list-manage.com","uuid":"a16126f77b33bc58d8eef3c50","lid":"a69743e135","uniqueMethods":true}) })</script>

I think this webpage will help you with your problem https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onload The onload function in javascript allows you to execute code when the page has been loaded. 我认为此网页将帮助您解决问题https://developer.mozilla.org/zh-CN/docs/Web/API/GlobalEventHandlers/onload javascript中的onload函数允许您在页面加载后执行代码。

Otherwise you could add a function call to the next script you want to execute, after the first one has finished executing. 否则,您可以在第一个脚本执行完毕后,将函数调用添加到要执行的下一个脚本中。

try somthing like this after animation end 动画结束后尝试这样的事情

var linkafterpreload = "link 1";

window.addEventListener("load", _ => {
    var newscript = document.createElement("script");
    newscript.src = linkafterpreload ;
    document.body.appendChild("newscript")
})

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

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