Now I'm trying to write a jquery function that allows me to expand a div when you click on it, and then return it to its original size when you click it again.
I tried adding a button to cancel it, but since when I click on it, the script thinks that I also click on the parent div and expand again. Ideally, I would like to do this without a button.
The code I have is
(jsfiddle): https://jsfiddle.net/Nikf/wykL6u7u/9/
<div class="grid"> <div class="block" id="block1"> <button class="retractor" id="ret1">back</button> </div> <div class="block" id="block2">2</div> <div class="block" id="block3">3</div> <div class="block" id="block4">4</div> <div class="block" id="block5">5</div> <div class="block" id="block6">6</div> </div>
CSS
*{ margin: 0; padding: 0; } html, body{ width: 100%; height: 100%; } .grid{ width: 100%; height: 100%; } .block{ width: 33.3%; height: 50%; float: left; color: #FFFFFF; position: relative; } .retractor{ width: 50px; height: 50px; padding: 10px 0; text-align: center; background-color: #FF0000; color: #FFFFFF; font-family: 'Open Sans', sans-serif; position: absolute; bottom: 30px; right: 30px; } #block1{ background-color: #222222; } #block2{ background-color: #999999; } #block3{ background-color: #5555555; } #block4{ background-color: #999999; } #block5{ background-color: #333333; } #block6{ background-color: #CCCCCC;
Script
$('#block1').click(function(){ $('#block1').animate({ width: '100%', height: '100%' }); }); $('#block1').click(function(){ $('#block1').animate({ width: '33.3%', height: '50%' }); });
Uesls source share