I have a jfiddle below that has two links that expand two divs independently and horizontally.
http://jsfiddle.net/j9W7R/
How would I go about causing only one div to be seen any any given time? Say you click the first one, then click the second and it causes the first to contract. Or if you click the first and click the first again it would also retract.
The idea is that the link will be a Facebook icon, the next link will be another social media icon, etc. etc. and I will embed a little “like us” or some sort of interaction with user.
You can do it next way:
To all your sliding
<div>s add some class.class="slickbox"for example.And each
.click()start with$('.slickbox').hide();hiding all boxes first and than expanding the one you need.For e.g.:
And one of
clicks will look like this.This way you can extend your
Like Useasily adding new items without writing.hide()for each opened/closed item.UPDATE: And if you need to close item if user again clicks on it, you can change
show/hidesection of the button.click()handler to the following.:hiddenselector will track the state of object visibility and basing on this you are deciding what to do with the box.