I have a dev page set up here: http://dev.harryg.me/da/
On the side I have 3 divs that should animate open when clicked and animate closed when the title is clicked again.
I wanted to add the functionality so that when the user clicks somewhere else on the document all the divs will close. This almost works great, except that once a div has been opened and closed as a result of clicking outside the user must click twice on it to reopen it.
Any idea of the cause?
Here is my jQuery…
jQuery(function($) {
$('h2.tab-title').toggle(function() {
$(this).parent().animate({left:'0px'}, {queue:false, duration: 500});
}, function() {
$(this).parent().animate({left:'-338px'}, {queue:false, duration: 500});
});
});
jQuery(".side-tab").click(function(){ return false; });
jQuery(document).bind("click", function() { jQuery(".side-tab").animate({left:'-338px'}, {queue:false, duration: 500}); });
demo
Create an open and close event and trigger one or the other on subsequent clicks, trigger close on document click.
JS