jquery implements dynamic load effects on list content _jquery

Source: Internet
Author: User

The dynamic update effect of the list data with jquery implementation, the updated data can be the AJAX request data.

Css:

. main {
 width:100%;
 margin-top:100px;
 Text-align:center;
 font-size:12.5px;
}

Th, TD {
 border:1px solid #ccc;
 line-height:40px;
 padding-left:5px
}
. Item:hover {
 background-color: #efefef;
}
. Item:nth-child (2n) {
 background-color: #efefef;
}
. ListView {
 width:600px;
 Overflow:hidden;
 margin:0 Auto;
 padding:10px;
 height:372px;
 border:1px solid #dddddd;
ListView. c {
 width:1200px;
 margin:0 Auto;
 Border-collapse:collapse
}
. Item {
 border-bottom:1px dashed #dddddd;
 padding:10px 0 10px 0;
 Overflow:hidden;
 margin-left:600px
}
. Item span {
 float:left;
 Text-align:left
}
. Item span:first-child {
 color: #6AA8E8;
}
. Item span:last-child {
 text-align:center
}

Html

<div class= "main" > <div class= "ListView" > <div class= "C" > <div class= "Item" > <span>tes t</span> <span> male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </span> <span> details </span> </div> <div class= "Item" > <span>test</span> <span> male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </span> <span> details </span> </div> <div class= "Item" > <span>test</span
  > <span> male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </span> <span> details </span> </div> <div class= "Item" > <span>test</span> <span> male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </ span> <span> details </span> </div> <div class= "Item" > <span>test</span> <span > Male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </span> <span> details </span> </div> <div class= "Item" > <span>test</span> <span> male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </span> <span> details </span> </div> <div class= "Item" > <span> test</span> <span> male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </span> <span> details </span> </div> <div class= "Item" > <span>test</span> <span> male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </span> <span> details </span> </div> <div class= "Item" > <span>test</span
  > <span> male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </span> <span> details </span> </div> <div class= "Item" > <span>test</span> <span> male/0</span> <span> Sichuan Province, Chengdu, Jinjiang District </ Span> <span> Detailed description </span> </div> </div> </div> </div> <p style= "Text-align: Center; " ><a href= "javascript:void (0);" onclick= "listview.update ();"
 > Refresh Data </a></p>

Js

<script type= "Text/javascript" src= "/js/jquery-1.8.0.min.js" ></script>
<script type= "text/" JavaScript ">
$ (function () {
 listview.init ();
});
var listview={
 init:function () {
 $ (". Item span "). CSS (" width ", $ (". ListView "). Width ()/4+" px ");
 For (var i=0;i<$ (). Item "). length;i++) {
 var target=$ (". Item ") [i];
 $ (target). Animate ({marginleft: "0px"},300+i*100);
 }
 },
 update:function () {
 $ (". ListView. C. Item "). Remove ();
 for (Var i=0;i<10;i++) {
 var newitem=$ ("<div class=\ item\" > <span>test</span> <span> Male/"+i+" </span> <span> Sichuan Province, Chengdu, Jinjiang District </span> <span> details </span> </div> ");
 $ (newitem). FIND ("span"). CSS ("width", $ (". ListView "). Width ()/4+" px ");
 $(". ListView. C "). Append (newitem);
 $ (newitem). Animate ({marginleft: "0px"},300+i*100);
}} </script>

Attach Demo effect Http://demo.jb51.net/js/2015/jquery-dtlb

The effect is not very good, and then we look at the waterfall flow of the implementation of ideas and JS control dynamically loaded code

The following code is mainly about loading events that control the scroll bar dropdown.

The code below shows that you can write your actions, whether loading pictures or loading record data.

Don't forget to quote the jquery class library.

 $ (window). Scroll (function () {
  var scrolltop = $ (this). ScrollTop ();
  var scrollheight = $ (document). Height ();
  var WindowHeight = $ (this). Height ();
  if (scrolltop + windowheight = = scrollheight) {

  //Here is the event triggered by the scroll bar to the bottom, where the data to be loaded is written, or the action to pull the scroll bar is

//var page = number ($ ("#redgiftNextPage"). attr (' currentpage ')) + 1;
Redgiftlist (page);
$ ("#redgiftNextPage"). attr (' currentpage ', page + 1);

  }
 });

Analytical:

To determine the scroll bar to the bottom, you need to use the DOM's three property values, namely ScrollTop, ClientHeight, ScrollHeight.
ScrollTop is the scroll distance of the scroll bar on the y-axis.
ClientHeight is the height of the content viewable area.
ScrollHeight adds an overflow (scrolling) distance to the height of the content viewable area.
From the introduction of this three attributes can be seen, the scroll bar to the bottom of the condition is scrolltop + clientheight = = ScrollHeight. (compatible with different browsers).

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.