/** * simple load more * * version: 1.0.2 * author: zeshan ahmed * website: https://zeshanahmed.com/ * github: https://github.com/zeshanshani/simple-load-more/ */ (function($) { $.fn.simpleloadmore = function( options ) { // settings. var settings = $.extend({ count: 5, btnhtml: '', item: '' }, options); // variables var $loadmore = $(this); // run through all the elements. $loadmore.each(function(i, el) { // variables. var $thisloadmore = $(this); var $items = $thisloadmore.find(settings.item); var btnhtml = settings.btnhtml ? settings.btnhtml : '加载更多'; var $btnhtml = $(btnhtml); // add classes $thisloadmore.addclass('load-more'); $items.addclass('load-more__item'); // add button. if ( ! $thisloadmore.find( '.load-more__btn' ).length && $items.length > settings.count ) { $thisloadmore.append( $btnhtml ); } $btn = $thisloadmore.find( '.load-more__btn' ); // check if button is not present. if not, then attach $btnhtml to the $btn variable. if ( ! $btn.length ) { $btn = $btnhtml; } if ( $items.length > settings.count ) { $items.slice(settings.count).hide(); } // add click event on button. $btn.on('click', function(e) { e.preventdefault(); var $this = $(this), $updateditems = $items.filter(':hidden').slice(0, settings.count); // show the selected elements. if ( $updateditems.length > 0 ) { $updateditems.fadein(); } // hide the 'view more' button // if the elements lenght is less than 5. if ( $updateditems.length < settings.count ) { $this.remove(); } }); }); } }( jquery ));