Created
April 24, 2012 09:16
-
-
Save Victa/2478169 to your computer and use it in GitHub Desktop.
jquery expand content
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
| <div id="lastest-video" class="hidden"> | |
| .... | |
| </div> | |
| <a href="#lastest-video" class="btn btn-allwidth expand-trigger" data-expand-text="view more latest videos +" data-collapse-text="collapse latest video -"> | |
| view more latest videos + | |
| </a> | |
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
| (function($){ | |
| $.fn.expandContent = function(settings) { | |
| var defaultSettings = {}, $elem, $content; | |
| settings = $.extend({}, defaultSettings, settings || {}); | |
| var toggleContent = function toggleContent(){ | |
| $content.slideToggle(240, function(){ | |
| changeLabel(); | |
| }); | |
| }; | |
| var changeLabel = function changeLabel(){ | |
| var text = ($content.css('display') === 'none') ? $elem.attr('data-expand-text') : $elem.attr('data-collapse-text'); | |
| $elem.html( text ); | |
| }; | |
| return this.each(function() { | |
| $elem = $(this); | |
| $content = $($elem.attr('href')); | |
| $elem.on('click', function(e){ | |
| e.preventDefault(); | |
| toggleContent(); | |
| }); | |
| }); | |
| }; | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment