Skip to content

Instantly share code, notes, and snippets.

@r38y
Created October 14, 2010 17:54
Show Gist options
  • Save r38y/626662 to your computer and use it in GitHub Desktop.
Save r38y/626662 to your computer and use it in GitHub Desktop.
// this is a fix for the jQuery slide effects
// found here: http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation
function slideToggle(el, bShow){
var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
// if the bShow isn't present, get the current visibility and reverse it
if( arguments.length == 1 ) bShow = !visible;
// if the current visiblilty is the same as the requested state, cancel
if( bShow == visible ) return false;
// get the original height
if( !height ){
// get original height
height = $el.show().height();
// update the height
$el.data("originalHeight", height);
// if the element was hidden, hide it again
if( !visible ) $el.hide().css({height: 0});
}
// expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
if( bShow ){
$el.show().animate({height: height}, {duration: 250});
} else {
$el.animate({height: 0}, {duration: 250, complete:function (){
$el.hide();
}
});
}
}
// clear bound events so we only get the one below
// I can be deleted if nothing is bound to these elements
$("#sites .close, strong.cog a").unbind();
$("#sites .close, strong.cog a").click(function(){
slideToggle("#sites");
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment