ul {
list-style: none;
}
li {
width: 40px;
height: 100px;
background: red;
display: inline-block;
margin-right: 20px;
margin-bottom: 5px;
}
JavaScript
(function($) {
// This function takes two optional parameters:
// The first is the text to be displayed
// The other is the number of elements that the text should be appended after (generally assuming this is being used on an <li>
var methods = {
init: function(options) {
// Create some defaults, extending them with any options that were provided
var settings = $.extend({
'toggleText': 'Show more...',
'wrapAfter': '5' // number of elements to start wrapping after
}, options);
return this.each(function() {
var wrapAfter = $(this).find('li').eq(options.wrapAfter - 1);
wrapAfter.nextAll().wrapAll('<div id="js-hidden-area" style="display: none;" />');
// Tooltip plugin code here
$(this).append('<a href="#" id="js-hide-toggle-text">' + settings.toggleText + '</a>');
$('#js-hide-toggle-text').click(function() {
$('#js-hidden-area').slideToggle();
});
});
}
};
$.fn.toggleText = function(method) {
// Method calling logic
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
return false;
}
};
$('.js-hide-toggle').toggleText({
'toggleText': 'Show all galleries',
'wrapAfter': '7'
});
})(jQuery);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.