简体   繁体   English

单击添加类然后删除的jQuery Modal

[英]Jquery Modal on click add class then remove

This bit of code is supposed to add a class and then with a delay remove the div entirely. 这段代码应该添加一个类,然后延迟删除整个div。 It just jumps to deleting the div. 它只是跳转到删除div。 Any ideas why? 有什么想法吗?

The HTML HTML

 <!-- modal conent-->
    <div class="modal" id="modal">
     <div class="modal-content ">
      <h1>Tricks Are 4 Kids</h1>
     <p>Ok so my modal doesn't look like this one, but this is it boiled down. Can I write the JS better??? ....</p>
       <button href="#" class="close" id="close" >X</button>
      </div>
    </div>
    </div>
 <!-- page conent-->
    <div id="page-content-wrapper" >I am a div with all the page conent. lalalalala</div>

The CSS CSS

.red {background:red;}

The jQuery jQuery的

$(document).ready( function() {
    $( "#close" ).click(function() {
        $("#modal").addClass("red").delay(800).queue
        $("#modal").remove();
    });

Codepen https://codepen.io/Ella33/pen/GjQZRP Codepen https://codepen.io/Ella33/pen/GjQZRP

$(document).ready( function() {
  $( "#close" ).click(function() {
    $("#modal").addClass("red");
    setTimeout(function() {
        $("#modal").remove();
    }, 800); 
});

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

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