Demo: http://jsfiddle.net/sunnycpp/fMXyP/5/
Consecutive show,hide calls produces a bug, Animation stops and does not resume sometimes. Is this jQuery bug or bug in my code?
Here is the code copy-pasted from jsfiddle.
myButtonManual.on("click", function() {
isVisible = !isVisible;
myHero.stop(true,false);
if(isVisible) {
myHero.show('slow');
myButtonManual.text("Manual Hide");
} else {
myHero.hide('slow');
myButtonManual.text("Manual Show");
}

That isn’t a bug.
Taking a look at this line:
When you stop a
.hide()at the middle of it without jumping to the end of animation, an element that is visible will stayvisible.Your logic
isVisible = !isVisiblewill be broken then as.stop()ing ahide()leaves the element still visible, meaning that the next call to the handler will execute.show()on avisibleelement that will have absolutely no effect.Workarounds include:
Remove the
.stop(), this will queue theshow()and execute it after thehide()concludes;Use
.stop(true)– equivalent to.stop(true, true)-, this will be rather bluntly as it will force the animation to conclude as it suddenly starts the next;Edit: The closest way to reproduce a
.toggle()-like behavior using the.show()and.hide()methods is to simply add a.css('display', 'none')before calling.show(), this will ensure that.show()has the desired effect:Fiddle
If the element is already hidden, the
.csswill have no effect; if the element is partially shown, it will hide it ensuring that.show()executes instead of being ignored due to the element being consideredvisible.This has the same effect as the
.stop(true, false).toggle(), but works using the 2 different.show()/.hide()methods as requested.