Created
October 27, 2011 00:03
-
-
Save karlbright/1318395 to your computer and use it in GitHub Desktop.
Fixing some of Jesse's code. Example of using jquery extend functionality.
This file contains hidden or 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.modalize = function(){ | |
$(this).each(function(i,v){ // Iterate over each of the elements | |
var el = $(v), popup = el.prev('.popup'); | |
el.bind('input', function(){ // When the user types within input... | |
if(popup.is(':hidden')) el.prev('.popup').fadeIn(100); // Grab previous sibling with class of 'popup' | |
}); | |
el.bind('focusout', function(){ // When focus leaves this element... | |
$('.popup').fadeOut(300); // Fade all popups out | |
}); | |
}) | |
return this; // Return elements so you can chain methods - example: $('input').modalize().show(); | |
}; | |
$(function(){ | |
$("input").modalize(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment