目录
一、pic1.html页面代码如下:
二、模拟数据库数据的实体类Photoes.cs代码如下:
三、服务器返回数据给客户端的一般处理程序Handler1.ashx代码如下:
四、示例下载:
五、了解更多瀑布流布局的的知识
首先给大家看一下瀑布流布局与无限加载图片相册效果图:
一、pic1.html页面代码如下:
* {
margin: 0;
padding: 0;
}
body {
background: url(../img/bg5.jpg);
}
#items {
width: 1060px;
margin: 0 auto;
border: 1px solid lightpink;
}
.item {
border: 1px solid lightpink;
width: 200px;
color: purple;
font-size: 30px;
font-weight: bolder;
margin: 5px;
text-align: center;
opacity: 0.8;
}
img {
width: 200px;
}
//此方法用来初始化图片(图片全部加载完成时调用)
var init = function () {
imagesLoaded(document.querySelector('#items'), function (instance) {
//此方法用来设置瀑布流布局
var msnry = new Masonry("#items", {
itemSelector: ".item",
columnWidth: 0 //列与列之间的宽度
});
//alert('所有的图片都加载完成了');
});
}
init();
var num = 0;
//此方法是无限加载的方法
$("#items").infinitescroll({
navSelector: "#next",
nextSelector: "a#next",
itemSelector: ".item",
debug: true,
dataType: "json",
maxPage: 10,
appendCallback: false,
path: function (index) {
console.log(index);
return "Handler1.ashx?page=" + index;
}
}, function (data) {
num -= 20;
|
二、模拟数据库数据的实体类Photoes.cs代码如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
namespace瀑布流布局与无限加载图片相册
{
publicclassPhotoes
{
publicintimgUrl {get;set; }
publicstringName {get;set; }
//模拟数据库有两百条数据
publicstaticList
{
List
Photoes pic =null;
for(inti= 21; i <=200; i++)
{
pic =newPhotoes();
pic.imgUrl = i;
pic.Name ="Picture-"+ i;
list.Add(pic);
}
returnlist;
}
}
}
|
三、服务器返回数据给客户端的一般处理程序Handler1.ashx代码如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Script.Serialization;
namespace瀑布流布局与无限加载图片相册
{
///
/// 服务器返回数据给客户端的一般处理程序
///
publicclassHandler1 : IHttpHandler
{
publicvoidProcessRequest(HttpContext context)
{
context.Response.ContentType ="text/plain";
List
intpageIndex = Convert.ToInt32(context.Request["page"]);
var filtered = result.Where(p => p.imgUrl >= pageIndex * 20 - 19 && p.imgUrl <= pageIndex * 20).ToList();
JavaScriptSerializer ser =newJavaScriptSerializer();
stringjsonData = ser.Serialize(filtered);
context.Response.Write(jsonData);
}
publicboolIsReusable
{
get
{
returnfalse;
}
}
}
}
|
总结:前段时间学习了瀑布流布局与图片加载等知识,做了一个简单的示例,希望能巩固一下自己所学的知识。
荒野乱斗国际版 (BrawlStars)最新版本v56.274
下载一波超人内置修改器菜单版 安卓版v1.0.2
下载敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载继承了一座戏园子无限声望铜钱版 内置菜单最新版v1.7
继承了一座戏园子折相思版是游戏的破解版本,在该版本中为玩家提
山河半世橙光清软金手指版 无限鲜花v3.24
山河半世是一款超级好玩的橙光恋爱游戏,在游戏中玩家们需要扮演
蓬莱手游折相思版 安卓版v1.0.0
蓬莱免广告版是游戏的修改版本,在该版本中为玩家去除了广告,玩
当红影后橙光游戏破解版2025 最新版v1.0
当红影后橙光破解版是一款超级好玩的娱乐圈题材的橙光游戏,在这
忽然成了万人迷清软完结版 无限鲜花版v12.15
忽然成了万人迷破解版是一款非常好玩的男性向橙光游戏,在有一天