简体   繁体   English

为什么执行此javascript会有滞后?

[英]why is there a lag in executing this javascript?

I want to run a - accept our terms pop up box - that must be accepted before the page can be seen. 我想运行一个-接受我们的条款弹出框-在显示该页面之前必须先接受该框。 I think I found answers here: https://stackoverflow.com/questions/6588167/how-do-i-make-a-popup-appear-immediately-before-the-rest-of-the-page-loads 我想我在这里找到了答案: https : //stackoverflow.com/questions/6588167/how-do-i-make-a-popup-appear-immediately-before-the-rest-of-the-page-loads

But I am at a loss to what I was doing wrong, and why my method had a time lag. 但是我对我做错的事情以及为什么我的方法有时间滞后感到茫然。

I uploaded http://jsfiddle.net/ZqVuj/2/ as example - If you click run you can see the lorem pops up for a moment then black. 我以http://jsfiddle.net/ZqVuj/2/为例上传-如果单击运行,您会看到lorem弹出一会儿,然后变黑。 Why does the modal not work before the rest of the page loads? 为什么模式在页面其余部分加载之前不起作用?

Someone built the page Im on off the code from this page: http://www.queness.com/post/77/simple-jquery-modal-window-tutorial 有人在此页面上的代码的基础上构建了Im页面: http//www.queness.com/post/77/simple-jquery-modal-window-tutorial

I took out the fade-ins, and changed $(document).ready(function() to $(function() 我取出淡入淡出,然后将$(document).ready(function()更改为$(function()

Yet the text still loads for a moment before the modal kicks in. What am I doing wrong? 然而,文本仍然会加载一小段时间,然后才能开始运行。我在做什么错?

Instead of $(function() {...}) , use (function() { ... })(); 代替$(function() {...}) ,使用(function() { ... })(); and put it right at the top of the <body> . 并将其放在<body>的顶部。 That way, it will run instantly before the page content is shown. 这样,它将在显示页面内容之前立即运行。

Bear in mind, though, that anyone with basic knowledge of their browser can just remove the popup and reveal the content. 但是请记住,任何具有浏览器基础知识的人都可以删除弹出窗口并显示内容。 You should use a more reliable method for securing your content. 您应该使用一种更可靠的方法来保护您的内容。

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

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