前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >仿qq空间好友动态刷新

仿qq空间好友动态刷新

作者头像
OECOM
发布2020-07-02 10:07:33
1.4K0
发布2020-07-02 10:07:33
举报
文章被收录于专栏:OECOM

在qq空间里有好多网页特效值得初学html和js的去学习,今天我来介绍一种特效。我们在上qq空间是都会发现,当向下滚动鼠标,使滚动条到达最低端的时候,好友动态会自动增加。这种特效其实很简单,多余的不说了,直接上代码:

获取滚动条当前位置:

代码语言:javascript
复制
function getScrollTop() { 
	var scrollTop = 0; 
	if (document.documentElement && document.documentElement.scrollTop) { 
	scrollTop = document.documentElement.scrollTop; 
	} 
	else if (document.body) { 
	scrollTop = document.body.scrollTop; 
	} 
	return scrollTop; 
	} 

获取当前可视范围的高度:

代码语言:javascript
复制
function getClientHeight() { 
	var clientHeight = 0; 
	if (document.body.clientHeight && document.documentElement.clientHeight) { 
	     clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight); 
	} 
	else { 
	clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight); 
	} 
	return clientHeight; 
	}

获取文档完整的高度 :

代码语言:javascript
复制
function getScrollHeight() { 
	return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); 
	} 

当到达底部是自动增加行:

代码语言:javascript
复制
window.onscroll = function () { 
		if (getScrollTop() + getClientHeight() == getScrollHeight()) {
                var newnode = document.createElement("a"); 
		newnode.setAttribute("href", "#"); 
		newnode.innerHTML = "new item"; 
		document.body.appendChild(newnode); 
		var newline = document.createElement("br"); 
		document.body.appendChild(newline); 
}

这些都是js代码,可以提供一个小例子来演示一下:

代码语言:javascript
复制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
 	window.onscroll = function () { 
		if(getScrollTop() + getClientHeight() == getScrollHeight()) {
                var newnode = document.createElement("a"); 
		newnode.setAttribute("href", "#"); 
		newnode.innerHTML = "new item"; 
		document.body.appendChild(newnode); 
		var newline = document.createElement("br"); 
		document.body.appendChild(newline); 
			} 
		}
	//获取滚动条当前的位置
	function getScrollTop() { 
	var scrollTop = 0; 
	if (document.documentElement && document.documentElement.scrollTop) { 
	scrollTop = document.documentElement.scrollTop; 
	} 
	else if (document.body) { 
	scrollTop = document.body.scrollTop; 
	} 
	return scrollTop; 
	} 
	
	//获取当前可是范围的高度 
	function getClientHeight() { 
	var clientHeight = 0; 
	if (document.body.clientHeight && document.documentElement.clientHeight) { 
	clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight); 
	} 
	else { 
	clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight); 
	} 
	return clientHeight; 
	} 
	
	//获取文档完整的高度 
	function getScrollHeight() { 
	return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); 
	} 

</script>
</head>

<body>
<ul>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
<li>啦啦啦啦啦啦啦啦啦</li>
</ul>

</div>
</body>
</html>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-04-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档