PHPCMS List page JS implementation load more effects

Source: Internet
Author: User

First look at the effect:

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/A4/8D/wKioL1mtXzSDg9XEAAB56QVVatc502.png-wh_500x0-wm_ 3-wmp_4-s_1899872139.png "title=" Qq20170904220845.png "alt=" Wkiol1mtxzsdg9xeaab56qvvatc502.png-wh_50 "/>

Display 6 data By default, click once to load more append display 6, until the full display of data, hide load more buttons.


The list page introduces the file:

<script type= "Text/javascript" src= ". /jquery-1.8.3.min.js "></script><script type=" Text/javascript "src=". /jquery.showmore.js "></script><script type=" Text/javascript ">//Call show more plugins. The parameter is the standard jquery selector $.showmore (". Showmorenchildren,.clearfix");</script>


Where the core JS file jquery.showMore.js

 javascript document (function  ()  {  var showMoreNChildren =  function  ($children,  n)  {    //shows the first n hidden child elements under a jquery element      var  $hiddenChildren  =  $children. Filter (": hidden");     var cnt  =  $hiddenChildren .length;    for  (var i = 0; i  < n && i < cnt ; i++)  {        $hiddenChildren. EQ (i). Show ();     }    return cnt -  n;//returns the number of hidden child elements that are still remaining   }    jQuery.showMore = function  ( Selector)  {    if  (selector == undefined)  { selector =   ". Showmorenchildren"  }    //The elements of an existing class=showmorehandle in the page, after which you add more bars to show, and bind the point-and-click behavior     $ (selector). EACH (function  ()  {      var pagesize = $ (this). attr (" PageSize ")  | |  10;      var  $children  = $ (this). Children ();       if  ($children. length > pagesize)  {         for  (var i = pagesize; i <  $children. length;  i++)  {           $children. EQ (i). Hide ();         }          $ ("< div class= ' showmorehandle '  > load More </div> "). InsertAfter ($ (this)). Click (function  ()  {           if  (Showmorenchildren ($children,  pagesize)  <= 0)  {            // If the target element already has no hidden child elements, it hides the"Click More button Bar"             $ (this). Hide ();           };        });       }    });   }) ();


Principle:

On the page is all the data, just follow the page display requirements, their own provisions show part of the scope, the rest hidden. If there is data, click Load More, continue to append a few data, until there is no more data, the load more buttons will be hidden.

This article is from the "jack_phpcms" blog, make sure to keep this source http://maifang158.blog.51cto.com/5433990/1962671

PHPCMS List page JS implementation load more effects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.