[英]How to create a time delay modal (preferably using HTML, JQuery, CSS)
I want to create a 5s time delay modal like this 我想创建一个5s的延时模式
I have done many googling and research but have been stuck with creating a modal like this that is not triggered by a button. 我做了很多谷歌搜索和研究工作,但一直坚持创建这样一个模态,该模态不是由按钮触发的。 I tried following the instructions (using just javascript) from W3Schools https://www.w3schools.com/bootstrap/bootstrap_ref_js_modal.asp and https://www.w3schools.com/howto/howto_css_modals.asp but nothing works. 我尝试按照W3Schools https://www.w3schools.com/bootstrap/bootstrap_ref_js_modal.asp和https://www.w3schools.com/howto/howto_hows_css_modals.asp上的说明进行操作(仅使用JavaScript),但没有任何效果。 And both are trigged by a button. 两者都可以通过按钮触发。
I don't know if it is because I am using JQuery codes for featherlight and slider. 我不知道是否是因为我正在为羽毛灯和滑块使用JQuery代码。 I also tried following the site https://www.sitepoint.com/show-modal-popup-after-time-delay/ but nothing pops up. 我还尝试关注该网站https://www.sitepoint.com/show-modal-popup-after-time-delay/,但没有任何提示。 I will appreciate a lot someone can kindly help and provide me with relevant scripts/css/js codes as I am quite new to coding. 我将不胜感激,有人可以提供帮助,并为我提供相关的脚本/ css / js代码,因为我是编码的新手。 Thank you so much! 非常感谢!
<div class="modal">
<div class="modal-content">
<span class="closebtn">×</span>
<h4>WELCOME</h4>
<label for="email">Don't miss out on the latest updates!</label>
<input placeholder="enter your email here" id="email">
<button class="subscribe">SUBSCRIBE</button>
</div>
</div>
I also tried using http://jquerymodal.com/ but does not work from a button nor I know how to use that with the settimeout
function without using a button to trigger the modal box. 我也尝试过使用http://jquerymodal.com/,但不能通过按钮使用,也不知道如何在不使用按钮触发模式框的情况下将settimeout
函数与之配合使用。
Please upload your code as well to see where you are wrong, Your approach is good but while questioning make sure that all elements are covered the languages tags, the reference and your code 请也上传您的代码,以查看您在哪里出错。您的方法不错,但在询问时请确保所有元素都覆盖在language标记,参考和代码中
Mostly these modals are used to display newsletters or any discount a site has to offer 通常,这些模式用于显示新闻通讯或网站必须提供的任何折扣
The code at the reference website looks good 参考网站上的代码看起来不错
You can put the code at end before the closing body tag in the script which will display the newsletter once the page is loaded and then add the time delay you want to set 您可以将代码放在脚本中结束body标记之前,在页面加载后将显示新闻稿,然后添加要设置的时间延迟
Assuming you want a modal that will automatically hide or disappear after a certain timeout, here's a JsFiddle that does it. 假设您想要一个在一定的超时后将自动隐藏或消失的模式,下面是一个JsFiddle可以做到的。
$(document).ready(function(){
$('#modal').click(function(){
$('#exampleModal').modal('show');
setTimeout(function() {$('#exampleModal').modal('hide');},
1000);
});
});
EDIT:: If you want your modal to load when the page loads (Not triggered by a button) you can just do: 编辑::如果您希望您的模式在页面加载时加载(不是由按钮触发),您可以执行以下操作:
$(document).ready(function(){
$('#exampleModal').modal('show');
setTimeout(function() {$('#exampleModal').modal('hide');},
1000);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.