Got a question involving some jQuery script I was putting together. I essentially have three elements each containing a background image that is set to 200px wide by default however if clicked, will grow to 300px.
Whenever you either click on one of the other two elements however, the other two shrink back to 200px. Also, if you click on the first element while it's open at 300px, it closes back to 200px so a toggle function is needed.
Here's what I have so far. Basically it works except a double click is required to reopen an element that has already been closed. Anyone know how to get around this tiny issue? I'm thinking I have to embed some sort of an "if/then" function. Code is below, thanks for taking a look!
------------------------------------------
Code:
<div class="back22"><a href="#">adfs</a></div>
<br /><br />
<div class="back33"><a href="#">adfs</a></div>
<br /><br />
<div class="back44"><a href="#">adfs</a></div>
<script>
$(".back22").toggle(function() {
$(".back22").animate({"width": "300px"}, "slow");
$(".back33").animate({"width": "200px"}, "slow");
$(".back44").animate({"width": "200px"}, "slow");
},
function() {
$(".back22").animate({"width": "200px"}, "slow");
});
$(".back33").toggle(function() {
$(".back33").animate({"width": "300px"}, "slow");
$(".back22").animate({"width": "200px"}, "slow");
$(".back44").animate({"width": "200px"}, "slow");
},
function() {
$(".back33").animate({"width": "200px"}, "slow");
});
$(".back44").toggle(function() {
$(".back44").animate({"width": "300px"}, "slow");
$(".back22").animate({"width": "200px"}, "slow");
$(".back33").animate({"width": "200px"}, "slow");
},
function() {
$(".back44").animate({"width": "200px"}, "slow");
});
</script>
Bookmarks