View页面。
@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#服务端:
List<int> vListInt = new List<int>();
for (int i = 0; i < 12; i++)
{
vListInt.Add(ro.Next(400, 500));
}
return Json(vListInt, JsonRequestBehavior.AllowGet);
}
新闻热点
疑难解答