Created
October 3, 2017 20:00
-
-
Save yairEO/d607ac7a53d2aa87aa7e67fe13b8f9d6 to your computer and use it in GitHub Desktop.
add temporary class
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
$.fn.addTempClass = function(tempClass, duration){ | |
if( !tempClass ) | |
return this; | |
return this.each(function(){ | |
var $elm = $(this), | |
timer; | |
$elm.addClass(tempClass); | |
// clear any timeout, if was any | |
clearTimeout( $elm.data('timeout') ) | |
timer = setTimeout(function(){ | |
$elm.removeClass(tempClass).removeData('timeout'); | |
}, duration || 100); | |
// set the timer on the element | |
$elm.data('timeout', timer); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: