时间:2021-05-19
View页面。
复制代码 代码如下:
@{
ViewBag.Title = "瀑布流";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@section header{
<script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
<style type="text/css">
.* {
margin:0px;
padding:0px;
}
body {
margin-left:auto;
margin-right:auto;
}
.ClearBoth {
clear:both;
}
#bodyContent {
width:1400px;
margin-left:auto;
margin-right:auto;
}
#head {
width:100%;
height:50px;
margin-bottom:10px;
}
#LefMenue {
width:20%;
height:500px;
float:left;
}
#RightContent {
width:75%;
float:right;
border: thin solid #333;
}
#Footer {
margin-top:10px;
width:100%;
height:40px;
}
.GreyBlock {
border: thin solid #333;
background-color:#CCC;
width:100%;
}
.Item {
float: left;
width: 230px;
margin:5px;
border: 1px solid #CCC;
}
</style>
}
<div id="bodyContent">
<div id="head" class="GreyBlock">
<h1>Head</h1>
</div>
<div>
<!--Left-->
<div id="LefMenue" class="GreyBlock">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
<!----right-->
<div id="RightContent">
<div id="ProductList">
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
<div class="Item">
<dl>
<dt>
<img src="~/Content/Shose.jpg" /></dt>
<dd>What's up with you</dd>
</dl>
</div>
</div>
</div>
<div class="ClearBoth"></div>
</div>
<div id="loading" class="loading-wrap">
<span class="loading">加载中,请稍后...</span>
</div>
<div class="ClearBoth"></div>
<div id="Footer" class="GreyBlock"></div>
</div>
@section scripts{
<script type="text/javascript">
var myContainer = $("#ProductList");
//用户拖动滚动条,达到底部时ajax加载一次数据
var loading = $("#loading").data("on", false);//通过给loading这个div增加属性on,来判断执行一次ajax请求
$(window).scroll(function () {
if ($("#loading").data("on"))//
{
return;
}
var isButtom = $(document).scrollTop() > ($(document).height() - $(window).height() - $("#Footer").height());
if (isButtom) {//页面拖到底部了
//加载更多数据
loading.data("on",true).fadeIn();
$.get("@Url.Action("GetData","Product")", function (data) {
var html = CreateHtml(data);
var $newElems = $(html).css({ opacity: 0 }).appendTo(myContainer);
$newElems.animate({ opacity: 1 },3000);
loading.data("on", false);
loading.fadeOut();
},"json");
}
});
function CreateHtml(data) {
var html = "";
if ($.isArray(data)) {
for (var i in data) {
//html += "<div class=\"Item\" style=\"height:"+data[i]+"px\">";
html += "<div class=\"Item\">";
html += "<dl>";
html += "<dt>";
html += "<img src=\"../Content/Shose.jpg\" />";
html += "</dt>";
html += "<dd>";
html += "What's up with you " + data[i];
html += "</dd>"
html += "</dl>"
html += "</div>"
}
}
return html;
}
</script>
}
C#服务端:
复制代码 代码如下:
public JsonResult GetData()
{
Random ro = new Random();
List<int> vListInt = new List<int>();
for (int i = 0; i < 12; i++)
{
vListInt.Add(ro.Next(400, 500));
}
return Json(vListInt, JsonRequestBehavior.AllowGet);
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
下面奉上一则用JS实现瀑布流的方法,望批评。复制代码代码如下:瀑布流布局测试body{background-color:#eee;font-size:84%;t
前言C#语言一贯秉承简洁优美的宗旨,每次升级都会带来一些语法糖,让我们可以使代码变得更简洁。本文分享两个使用C#9.0提升if语句美感的技巧示例。使用属性模式代
一、用C#将Image转换成byte[]并插入数据库:1.1 将图片控件的Image转换成流:复制代码代码如下:privatebyte[]PicToArray(
本文实例为大家分享了js瀑布流加载效果,动态加载图片,供大家参考,具体内容如下鼠标滚动事件,当鼠标滚动到下边,动态加载图片。1.HTML代码js实现瀑布流效果-
今天学习了一个瀑布流加载效果,很多网站都有瀑布流效果,瀑布流就是很多产品显示在网页上,宽相同,高度不同,表现为多栏布局,随着页面滚动条向下滚动,这种布局还会不断