Created
May 16, 2013 16:08
-
-
Save jibbius/5592898 to your computer and use it in GitHub Desktop.
jQuery - Expand & Collapse <div>s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Title</title> | |
<style type="text/css">body {background: rgb(253, 251, 207);}.fw_box {width: 430px;float: left;border-style: solid;border-width: 2px;border-radius: 10px;margin: 1px 10px 10px 10px;padding: 10px;position: inherit;border: 2px solid rgb(253, 250, 250);background-color: rgba(255, 255, 255, 0.5);color: #000000;}.fw_content {font-size: 0.8em;word-wrap: break-word;}.fw_box:hover .fw_content {display: block;overflow: auto;}.fw_title {font-size: 1.1em;text-align: center;vertical-align: middle;padding-top: 5px;font-weight: bold;}.fw_box:hover {background: rgba(255,165,165,0.5);}.fw_preview {float: right;width: 45%;height: 288px;background: white;margin: 10px;padding: 10px;border-style: solid;border-radius: 10px;}.fw_list {width: 100%;}.fw_row {width: 100%;overflow: auto;} | |
</style> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> | |
<script type="text/javascript"> | |
jQuery(document).ready(function(){ | |
/*hide the all of the element with class fw_body*/ | |
jQuery(".fw_content").hide(); | |
/*toggle the component with class fw_content.*/ | |
var $fw_box = jQuery(".fw_box"); | |
$fw_box.click(function(){ | |
var $self = jQuery(this); | |
/*display this*/ | |
$self.children(".fw_content").slideToggle(600); | |
/*hide others*/ | |
$fw_box.not($self).children(".fw_content").filter(":visible").hide(); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="fw_list"> | |
<div class="fw_row"> | |
<div class="fw_box"> | |
<div class="fw_title"> | |
Box 1 | |
</div> | |
<div class="fw_content" style="display: none;"> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
</p> | |
</div> | |
</div> | |
<div class="fw_box"> | |
<div class="fw_title"> | |
Box 2 | |
</div> | |
<div class="fw_content" style="display: none;"> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa, laborum illum a eius tempore sapiente iste ipsam libero consectetur fuga quas inventore odio minus officia dicta reprehenderit sint quaerat labore! | |
</p> | |
</div> | |
</div> | |
</div> | |
<div class="fw_row"> | |
<div class="fw_box"> | |
<div class="fw_title"> | |
Box 3 | |
</div> | |
<div class="fw_content" style="display: none;"> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expedita, culpa esse et necessitatibus perspiciatis. Reprehenderit, numquam, adipisci, non accusamus veritatis cum eos nobis corrupti doloremque similique tenetur eum dicta modi. | |
</p> | |
</div> | |
</div> | |
<div class="fw_box"> | |
<div class="fw_title"> | |
Box 4 | |
</div> | |
<div class="fw_content" style="display: none;"> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expedita, labore et nostrum hic tempore commodi quo accusantium rem consectetur itaque id qui iusto libero cum cupiditate. Expedita, ullam commodi necessitatibus? | |
</p> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function(){ | |
/*hide the all of the element with class fw_body*/ | |
jQuery(".fw_content").hide(); | |
/*toggle the component with class fw_content.*/ | |
var $fw_box = jQuery(".fw_box"); | |
$fw_box.click(function(){ | |
var $self = jQuery(this); | |
/*display this*/ | |
$self.children(".fw_content").slideToggle(600); | |
/*hide others*/ | |
$fw_box.not($self).children(".fw_content").filter(":visible").hide(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment