简体   繁体   English

尝试使用灯箱创建延迟弹出窗口

[英]Trying to Create a Delayed Pop-up with Lightbox

I'm trying to create a lightbox with Jquery that will open an email collection pop-up to sign up for a newsletter. 我正在尝试使用Jquery创建一个灯箱,它将打开一个电子邮件集合弹出窗口以注册一个新闻通讯。 I think I understand how to make it work if someone clicks on a link but I don't want the visitor to have to click a link, I want it to pop up automatically after say a 5 second delay when the visitor lands on the page as seems common on many pages. 我想我理解如果有人单击链接时如何使它起作用,但是我不希望访问者必须单击链接,我希望访问者在页面上停留5秒后自动弹出在许多页面上似乎很常见。 This is a non CMS page. 这是非CMS页面。 Can someone tell me the simplest way to go about this? 有人可以告诉我最简单的方法吗?

You can use setTimout() for that : 您可以使用setTimout()

setTimeout(function(){
   //This code will run in 5 seconds
}, 5000);

Here's a fiddle with an alert to demonstrate. 这是一个带有警告要演示的小提琴

So to do this add this code: 为此,请添加以下代码:

setTimeout(function(){ popupFunction(); }, 5000);

to your jquery window ready event: 到您的jquery窗口ready事件:

$(document).ready(function() {
   //add code here
   setTimeout(function(){ popupFunction(); }, 5000);
});

And then create a function that makes your popup work: 然后创建一个使弹出窗口起作用的函数:

function popupFunction(){ 
  //code here that works the popup
}

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

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