简体   繁体   English

如何创建时间延迟模态(最好使用HTML,JQuery,CSS)

[英]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.asphttps://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">&times;</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.

相关问题 如何在 HTML/CSS 中使用语义 UI 创建模态? - How can I create a modal using Semantic UI in HTML/CSS? 如何使用 CSS 和 Jquery 进行内容延迟 - How to make content delay using CSS and Jquery 如何使用javascript和CSS创建模态弹出窗口 - How to create a modal popup using javascript and CSS 如何使用HTML,CSS和JQuery在圆形设计中创建交互式导航 - How to create an interactive navigation, in a circular design, using HTML, CSS, and JQuery 如何在特定时间段后向div添加CSS规则,设置延迟,然后使用jquery添加一个CSS规则? - How can i add a css rule to a div after specific period of time, set a delay and then add one more css rule, using jquery? 如何使用HTML 5(最好)或javascript(不使用jquery)将文本输入限制为仅接受字母M和F - How to restrict a text input only to accept letter M and F using HTML 5(preferably) or javascript(no jquery) How to select HTML attributes from an Ajax HTML response preferably with jQuery? - How to select HTML attributes from an Ajax HTML response preferably with jQuery? 使用jQuery关闭延迟的Bootstrap模式 - Close Bootstrap modal on the delay using jQuery 如果我使用单独的html / css页面,如何创建模式弹出效果? - How can I create modal popup effect, If I'm using separate html/css pages? 具有jQuery Function的CSS动画具有延迟时间 - CSS animation with jQuery Function has Delay Time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM