Created
June 16, 2010 02:15
-
-
Save twalker/440047 to your computer and use it in GitHub Desktop.
A tiny jQuery plugin to reveal a target element from a triggering link.
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
/* | |
* revealMore | |
* | |
* A tiny jQuery plugin to reveal a target element from a triggering link. | |
* | |
* Usage: | |
* <a class="more_trigger" href="#more1">more...</a> | |
* <div id="more1">More Info</div> | |
* | |
* <script type="text/javascript"> | |
* $("a.more_trigger").revealMore({moreText: 'more stuff', lessText: 'less stuff'}); | |
* </script> | |
*/ | |
(function($) { | |
$.fn.revealMore = function(params) { | |
var options = $.extend({ | |
moreText: 'more...', | |
lessText: 'less...'}, params); | |
return this.each(function() { | |
var $lnk = $(this), $target = $($lnk.attr('href')); | |
if($target.length == 0) { | |
$lnk.hide(); | |
} else { | |
$target.hide(); | |
} | |
$lnk.toggle( | |
function(e){ | |
e.preventDefault(); | |
$(this).text(options.lessText).addClass('less'); | |
$($(this).attr('href')).slideDown('fast'); | |
}, | |
function(e){ | |
e.preventDefault(); | |
$(this).text(options.moreText).removeClass('less'); | |
$($(this).attr('href')).slideUp('fast'); | |
} | |
); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment