-
-
Save benscobie/205e7c1769f33576419d61ba0d6f2e0d to your computer and use it in GitHub Desktop.
jQuery's hide() and show() slow in Chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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