分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

ajax滚动条懒加载

发布时间:2023-09-06 02:08责任编辑:郭大石关键词:暂无标签

前端html

<div class="activity_box"> ?<ul class="clearfix" id="contact"> ????<!--内容--> ?</ul> ?<div id="loading" style="text-align: center"> ???<img src="/images/loading.gif" alt="" />正在加载数据,请稍候...
?</div></div>

前端JS:

<script> ???var pageindex = 1; ???var DataIsNull = false; ???function GetData(pageindex) { ???????var url = "ajax/do_data.ashx"; ???????var act = "activity"; ???????$.ajax({ ???????????type: "POST", ???????????url: url, ???????????dataType: "html", ???????????async: true, ???????????data: { ???????????????"act": act, ???????????????"page": pageindex ???????????}, ???????????beforeSend: function () { ???????????????ShowDiv(); ???????????}, ???????????complete: function () { ???????????????HiddenDiv(); ???????????}, ???????????success: function (data) { ???????????????if (data == "") { ???????????????????DataIsNull = true; ???????????????} ???????????????$("#contact").append(data); ???????????} ???????}); ???} ???GetData(pageindex); ???//显示加载数据 ???function ShowDiv() { ???????$("#loading").show(); ???} ???//隐藏加载数据 ???function HiddenDiv() { ???????$("#loading").hide(); ???} ???//滚动条滚动事件 ???$(window).scroll(function () { ???????if ($(document).scrollTop() + $(window).height() >= $(document).height()) { ???????????if (!DataIsNull) { ???????????????next(); ???????????} ???????} ???}); ???function next() { ???????pageindex++; ???????GetData(pageindex); ???}</script>

后端代码:

public void activity() ???{ ???????int maxPageSize = 8; ???????int pageID = Convert.ToInt32(HttpContext.Current.Request.Form["page"]); ???????int newsCount = BLLNewsInfo.GetRecordCount("");//新闻总数 ???????int PageCount = newsCount / maxPageSize + (newsCount % maxPageSize == 0 ? 0 : 1);//最大页数 ???????int MaxPerPage1 = pageID == PageCount ? (newsCount - (PageCount - 1) * maxPageSize) : maxPageSize; ???????if (pageID > PageCount) ???????{ ???????????HttpContext.Current.Response.Write(""); ???????} ???????else ???????{ ???????????News_InfoList = BLLNewsInfo.GetListByPage("1=1", " AddDate", MaxPerPage1, maxPageSize * pageID); ???????????StringBuilder html = new StringBuilder(); ???????????foreach (SHLY.Model.News_Info item in News_InfoList) ???????????{ ???????????????html.AppendLine("<li>"); ???????????????html.AppendLine("<a href=\"/news-" + item.Id + ".html\" title=\"" + item.Title + "\" >"); ???????????????html.AppendLine("<img src=\"" + item.TitlePic + "\"/>"); ???????????????html.AppendLine("</a>"); ???????????????html.AppendLine("<p><a href=\"/news-" + item.Id + ".html\" title=\"" + item.Title + "\" >"); ???????????????html.AppendLine("" + item.Title + "</a></p>"); ???????????????html.AppendLine("</li>"); ???????????} ???????????HttpContext.Current.Response.Write(html.ToString()); ???????} ???}

ajax滚动条懒加载

原文地址:https://www.cnblogs.com/zzx849918265/p/9436692.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved