Jquery Modal点击添加类然后删除

时间:2016-10-08 00:23:24

标签: javascript jquery html css

这段代码应该添加一个类,然后延迟删除div。它只是跳转到删除div。有什么想法吗?

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>

CSS

.red {background:red;}

jQuery

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

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

1 个答案:

答案 0 :(得分:0)

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