browser window scrolling load data in asynchronous form loading data from the background

Source: Internet
Author: User
Tags json

  Load data from the background in an asynchronous form when the scroll bar is at the top (the page exceeds the height of the window), and the following is a concrete implementation that you want to help with.

The following scrolling effect is found on the web.     Load data from the background in asynchronous form when the scroll bar is at the top (the page exceeds the height of the window)   code is as follows: <%@ page language= "C #" autoeventwireup= "true" Codebehind= "ScrollLoadData.aspx.cs" inherits= "Webapplication1.scrollloaddata"%>    <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">    <html xmlns=" http://www.w3.org/1999/xhtml ">  <head runat=" Server ">  < title> scrolling Load Database data </title>  <script src= "... /scripts/jquery-1.4.1-vsdoc.js "type=" Text/javascript "></script>  <script src=". /scripts/jquery-1.4.1.js "type=" Text/javascript "></script>  <script src=". /scripts/jquery-1.4.1.min.js "type=" Text/javascript "></script>  <script type=" Text/javascript " >  $ (document). Ready (function () {    var range = 50;//margin lower boundary length/unit px  var elemt = 500;//Insert element height/unit px   var maxnum = 20; Set load maximum times   var num = 1;  varTotalheight = 0;  var main = $ ("#content"); Principal element   $ (window). Scroll (function () {  var srollpos = $ (window). scrolltop ();//scroll bar distance from top (page exceeds height of window)     Totalheight = parsefloat ($ (window). Height ()) + parsefloat (srollpos);  if ((document). Height ()-range) <= totalheight && num!= maxnum) {  $.ajax ({  URL: ".. /demo/handlerdemo.ashx ",//Display data method page   type:" Get ",  data:" Name=json ",  dataType:" JSON ", //cache: false,  success:function (data) {  data = eval (data);  var varhtml = "";  varhtml = "<ul>" &nbsp ; $ (data). Each (function (i) {  varhtml + = "<li>" + data[i].id + ":" + data[i]. Event + "</li>"; ID and event for database mapped fields  });  varhtml + = "</ul>";  main.append ("<div style= ' border:0px solid Tomato;margin-top:20px;color: #ac "+ (num%) + (num%) +"; Height: "+ elemt +" ' >hello World "+ Srollpos +" <b R/> "+varhtml +---" + num + "</div>"); },  error:function () {  alert ("error"); }   });    num++; } }) ;  </script>  <style type= "text/css" >  li  {  list-style-type:none;  float: left;  padding-left:20px;   }  </style>  </head>  <body>  < Form id= "Form1" runat= "Server" >  <div id= "content" style= "height:960px" >  <div id= "Follow" > This is a scroll test;<br/> page drop-down auto load content </div>  <div style= ' border:1px solid; Color: #ac1 height:800 ' >hello World Test div</div>  </div>    </form>  </ body>  </html>   

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.