Giter Site home page Giter Site logo

oozrafa / hide-max-list-items-expander-jquery-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jawinn/hide-max-list-items-expander-jquery-plugin

0.0 1.0 0.0 21 KB

This jQuery plugin will automatically hide all excess list items past a maximum number. It then dynamically adds an expand/collapse link that uses the slideToggle effect. Each list item is collapsed in succession to give the appearance of using slideToggle on a container.

Home Page: http://www.joshuawinn.com/maximum-list-items-jquery-hide-after-x-number-bullets/

HTML 43.17% JavaScript 45.45% CSS 11.38%

hide-max-list-items-expander-jquery-plugin's Introduction

Expandable Maximum List Items jQuery Plugin

This jQuery plugin will automatically hide all excess list items past a maximum number. It then adds an expand/collapse link that uses the slideToggle effect to show/hide them. Each list item is collapsed in succession to give the appearance of using slideToggle (slideUp, SlideDown) on a container. The expand/collapse link can also include the number of items that are hidden.

USAGE EXAMPLE

Here’s a basic example:

$(document).ready(function() {
    $('#elementToApplyHere').hideMaxListItems({ 'max':4 });
});

PLUGIN OPTIONS

There are 5 available options; the maximum number of list items to show, the speed of the slide animation in milliseconds, the HTML used for the expand/collapse link, and the text used in this link.

It defaults to a max of 5, a speed of 1000 (ms), and a paragraph containing a link with “READ MORE”. Here’s an example with the options:

$(document).ready(function() {
    $('#content ul').hideMaxListItems({
        'max':6,
        'speed':2000,
    	'moreText':'READ MORE',
		'lessText':'READ LESS <em>Can Use HTML</em>',
        'moreHTML': '<p class="maxlist-more"><a href="#"></a></p>'
    });
});

Note that the expand/collapse container requires the “maxlist-more” class, and a child anchor tag. I've left his as an option in case you wanted to do something like:

'moreHTML': '<div class="maxlist-more someOtherClass"><span class="someOtherExampleWrapper"><a class="myButtonClass" href="#"></a></span></div>'

INCLUDE MAX ITEM COUNT

You also can display the number of additional list items in the moreText and lessText options. If you include the text "[COUNT]", it will be replaced with the number. Example:

$('#selector ul').hideMaxListItems({ 'max':3, 'moreText':'Read More ([COUNT])' }); 

If there were 10 items in the list, it would read: "Read More (7)"

HANDLING DYNAMIC UPDATES TO YOUR LIST

If you're adding or removing list items dynamically (such as with AJAX), simply call the hideMaxListItems function again in the same way that you initiated it, when your list changes. The plugin will avoid adding to the DOM by hiding/showing any existing Read More button, and will reset any items that were hidden previously.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.