Skip to content

Instantly share code, notes, and snippets.

@benscobie
Created August 4, 2018 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benscobie/205e7c1769f33576419d61ba0d6f2e0d to your computer and use it in GitHub Desktop.
Save benscobie/205e7c1769f33576419d61ba0d6f2e0d to your computer and use it in GitHub Desktop.
jQuery's hide() and show() slow in Chrome
var $cssSelector = "display";
var $hideCSS = "none";
var $showCSS = "block";
if ($.browser.chrome) {
$cssSelector = "margin-top";
$showCSS = "0";
$hideCSS = "-10000px";
}
$("#element").css($cssSelector, $showCSS); // For showing
$("#element").css($cssSelector, $hideCSS); // For hiding
(function($) {
var userAgent = navigator.userAgent.toLowerCase();
$.browser = {
version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
chrome: /chrome/.test( userAgent ),
safari: /webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
})(jQuery);
$element.css('margin-top', '0'); // For showing
$element.css('margin-top', '-1000000px'); // For hiding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment