jQuery实现模仿微博下拉滚动条加载数据效果
作者:bea
本文实例讲述了jQuery实现模仿微博下拉滚动条加载数据效果。分享给大家供大家参考,具体如下: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>滚动条距离底部</title> <script src="jquery-1.6.2.min.js" type="text/javascript"></script>
本文实例讲述了jQuery实现模仿微博下拉滚动条加载数据效果。分享给大家供大家参考,具体如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>滚动条距离底部</title>
<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var i = 4;
$(window).bind("scroll", function (event) {
//滚动条到网页头部的 高度,兼容ie,ff,chrome
var top = document.documentElement.scrollTop + document.body.scrollTop;
//网页的高度
var textheight = $(document).height();
// 网页高度-top-当前窗口高度
if (textheight - top - $(window).height() <= 100) {
if (i >= 100) {
return; //控制最大只能加载到100
}
$('#div1').css("height", $(document).height() + 100);
i++;
//可以根据实际情况,获取动态数据加载 到 div1中
$('<div>' + i + '</div>').appendTo($('#div1'));
}
});
})
</script>
<style>
#div1 div{ font-size:100px; background:#ccc;margin-top:5px}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 1000px;" id="div1">
<div>
1</div>
<div>
2</div>
<div>
3</div>
<div>
4</div>
</div>
</form>
</body>
</html>
希望本文所述对大家jQuery程序设计有所帮助。
有用 | 无用
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>滚动条距离底部</title>
<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var i = 4;
$(window).bind("scroll", function (event) {
//滚动条到网页头部的 高度,兼容ie,ff,chrome
var top = document.documentElement.scrollTop + document.body.scrollTop;
//网页的高度
var textheight = $(document).height();
// 网页高度-top-当前窗口高度
if (textheight - top - $(window).height() <= 100) {
if (i >= 100) {
return; //控制最大只能加载到100
}
$('#div1').css("height", $(document).height() + 100);
i++;
//可以根据实际情况,获取动态数据加载 到 div1中
$('<div>' + i + '</div>').appendTo($('#div1'));
}
});
})
</script>
<style>
#div1 div{ font-size:100px; background:#ccc;margin-top:5px}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 1000px;" id="div1">
<div>
1</div>
<div>
2</div>
<div>
3</div>
<div>
4</div>
</div>
</form>
</body>
</html>
希望本文所述对大家jQuery程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- Knockout自定义绑定创建方法
- JavaScript动态设置div的样式的方法
- JS插件overlib用法实例详解
- 如何解决easyui自定义标签 datagrid edit combobox 手动输入保存不上
- 认识Knockout及如何使用Knockout绑定上下文
- 详解Document.Cookie
- 不得不分享的JavaScript常用方法函数集(下)
- JQuery datepicker 用法详解
- 一道JS前端闭包面试题解析
- 干货分享:让你分分钟学会javascript闭包
- javascript生成img标签的3种实现方法(对象、方法、html)
- 谈谈我对JavaScript中typeof和instanceof的深入理解
- JavaScript中Window对象的属性及事件
- JavaScript字符串删除重复字符的方法
- JavaScript如何实现在文本框(密码框)输入提示语
- jquery实现图片预加载
- 基于jquery实现图片相关操作(重绘、获取尺寸、调整大小、缩放)
- 使用堆实现Top K算法(JS实现)
- 原生js和jQuery实现淡入淡出轮播效果