javascript - Expand multiple div on click and revert via close button -


i looked several questions of similar nature haven't found i'm looking for. have 6 divs on page (js fiddle here) , got them expand on click, after trying several snippets no closer getting close button work when started. pointers on how close expanded divs using close button!

markup:

    $('#div6, #div5, #div4, #div3, #div2, #div1').click(        function() {          $(this).animate({            'width': '100%',            'height': '100%'          }, 600).siblings().animate({            'width': '0',            'height': '0'          }, 600);          $('<button class="show">xclose</button>')            .appendto('.wrapper');        });        $('.show').click(function() {        $(this).animate({          'width': '0',          'height': '0'        }, 600).siblings().animate({          'width': '50%',          'height': '33.33%'        }, 600);        $(this).remove();      });
   html,     body {       height: 100%;       padding: 0;       margin: 0;     }     .wrapper {       width: 100%;       height: 100%;     }     #div1 {       width: 50%;       height: 33.33%;       float: left;       background-color: rgba(215, 176, 44, 0.9);       background: rgba(215, 176, 44, 0.9);       color: rgba(215, 176, 44, 0.9);       ;     }     #div1:hover {       z-index: 55555;       -moz-box-shadow: 5px 15px 5px #111;       -webkit-box-shadow: 5px 15px 5px #111;       box-shadow: 5px 15px 5px #111;     }     #div2 {       width: 50%;       height: 33.33%;       float: left;       background-color: rgba(100, 176, 176, 0.9);       background: rgba(100, 176, 176, 0.9);       color: rgba(100, 176, 176, 0.9);     }     #div2:hover {       z-index: 55555;       -moz-box-shadow: 5px 15px 5px #111;       -webkit-box-shadow: 5px 15px 5px #111;       box-shadow: 5px 15px 5px #111;     }     #div3 {       width: 50%;       height: 33.33%;       float: left;       background-color: rgba(129, 153, 92, 0.9);       background: rgba(129, 153, 92, 0.9);       color: rgba(129, 153, 92, 0.9);     }     #div3:hover {       z-index: 55555;       -moz-box-shadow: 5px 15px 5px #000;       -webkit-box-shadow: 5px 15px 5px #000;       box-shadow: 5px 15px 5px #000;     }     #div4 {       width: 50%;       height: 33.33%;       float: left;       background-color: rgba(253, 151, 0, 0.8);       background: rgba(253, 151, 0, 0.8);       color: rgba(253, 151, 0, 0.8);     }     #div4:hover {       z-index: 55555;       -moz-box-shadow: 5px 15px 5px #000;       -webkit-box-shadow: 5px 15px 5px #000;       box-shadow: 5px 15px 5px #000;     }     #div5 {       width: 50%;       height: 33.33%;       float: left;       background-color: rgba(255, 255, 0, 0.9);       background: rgba(255, 255, 0, 0.9);       color: rgba(255, 255, 0, 0.9);     }     #div5:hover {       z-index: 55555;       -moz-box-shadow: 5px 15px 5px #000;       -webkit-box-shadow: 5px 15px 5px #000;       box-shadow: 5px 15px 5px #000;     }     #div6 {       width: 50%;       height: 33.33%;       float: left;       background-color: rgba(191, 84, 61, 0.9);       background: rgba(191, 84, 61, 0.9);       color: rgba(191, 84, 61, 0.9);     }     #div6:hover {       z-index: 55555;       -moz-box-shadow: 5px 5px 15px #000;       -webkit-box-shadow: 5px 5px 15px #000;       box-shadow: 5px 5px 15px #000;     }     .active {       height: 100%;       width: 100%;     }     .hide {       display: none;     }     .auto-style1 {       font-family: georgia, "times new roman", times, serif;       font-size: large;       text-align: center;       vertical-align: middle;       color: #ffffff;       margin: 16vh auto auto auto;     }     #close {       float: right;       display: inline-block;       padding: 2px 5px;       background: #ccc;     }     #close:hover {       float: right;       display: inline-block;       padding: 2px 5px;       background: #ccc;       color: #fff;     }     .show {       position: absolute;       top: 9;       right: 0;       margin-left: -2.5em;       width: 15em;     }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="wrapper">    <div id="div1">    </div>    <div id="div2">      <p class="auto-style1">this div2</p>    </div>    <div id="div3">    </div>    <div id="div4">    </div>    <div id="div5">    </div>    <div id="div6">    </div>  </div>

use event delegation on dynamically created elements:

$(document).on('click','.show', function() {       $(this).animate({         'width': '0',         'height': '0'       }, 600).siblings().animate({         'width': '50%',         'height': '33.33%'       }, 600);       $(this).remove();     }); 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -