分享仿csdn滚动到顶部

一天要饭生活又开始啦 2013-05-14 05:41:15
    <!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 type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
var cW,cH;
function scrolls() {
cW = document.documentElement.clientWidth;
cH = document.documentElement.clientHeight;
var _div = document.createElement('div');
_div.className = 'divClass';
_div.appendChild(document.createTextNode('UP'));
_div.id = 'divId';
_div.onclick = function() {
//document.documentElement.scrollTop = '0';
$(document.documentElement).animate({'scrollTop': '0'}, 100);
document.getElementById('divId').style.display = 'none';
}
//_div.setAttribute('onclick', function() {
//document.documentElement.scrollTop = '0';
//document.getElementById('divId').style.display = 'none';

//});
document.body.appendChild(_div);
document.getElementById('divId').style.left = (cW - 40) + 'px';
document.getElementById('divId').style.top = (cH - 40) + 'px';

}
function shang() {
if(document.documentElement.scrollTop > 10) {
document.getElementById('divId').style.display = 'block';
} else {
document.getElementById('divId').style.display = 'none';
}
}
function resizediv() {
cW = document.documentElement.clientWidth;
cH = document.documentElement.clientHeight;
var scrollLeft = document.documentElement.scrollLeft;
var scrollTop = document.documentElement.scrollTop;
document.getElementById('divId').style.left = (cW - 40 + scrollLeft) + 'px';
document.getElementById('divId').style.top = (cH - 40 + scrollTop) + 'px';
}
window.onload = function() {
scrolls();
}
window.onresize = resizediv;
window.onscroll = function() {
shang();
resizediv();
}
</script>
<style type="text/css">
body { margin:0; padding:0; }
.divClass { width:40px; height:40px; background-color:black; filter:alpha(Opacity=80);-moz-opacity:0.5;opacity: 0.5; position:absolute; color:red; text-align:center; cursor:pointer; display:none; }
</style>
</head>
<body>
<div style='height:1000px;'></div>
</body>
</html>
...全文
49 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
顶。。。。。。。。。。。。。。。。。

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧