以下是 jQuery仿腾讯回顶部和建议 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!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=gb2312" />
<meta name="keywords" content="JS代码,{keyword},JS广告代码,JS特效代码" />
<meta name="description" content="此代码内容为{title},属于站长常用代码" />
<title>{title}</title><link type="text/css" href="css/lrtk.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/js.js"></script>
</head>
<body>
<div id="main" style="width:1000px; height:2000px; background:#eee; margin:0 auto;">
<div style="width:1000px;height:1000px;background:#75d0ff">内容</div>
<div id="tag_cmt" style="width:1000px; height:1000px; background:#669900;">评论</div>
</div>
<div id="tag_about" style="width:1000px; height:1000px; background:#F90; margin:0 auto;">相关</div>
<div style="font:normal 12px/2em '微软雅黑';text-align:center;margin:50px 0;">
</div>
<!-- 代码开始 -->
<div id="tbox">
<a id="pinglun" href="#tag_cmt"></a>
<a id="xiangguan" href="#tag_about"></a>
<a id="gotop" href="javascript:void(0)"></a>
</div>
<!-- 代码结束 -->
</body>
</html>
JS代码(js.js):
function b(){
h = $(window).height();
t = $(document).scrollTop();
if(t > h){
$('#gotop').show();
}
else{
$('#gotop').hide();
}
}
$(document).ready(function(e){
b();
$('#gotop').click(function(){
$(document).scrollTop(0);
}
)}
);
$(window).scroll(function(e){
b();
}
)
CSS代码(lrtk.css):
/* ת���뱣���Ȩ��Ϣ������ͼ�� www.lanrentuku.com */
*{padding:0px;margin:0px;}
*html{background-image:url(about:blank);background-attachment:fixed;}
/*���IE6�¹�������������*/
#tbox{width:54px;float:right;position:fixed;right:50px;bottom:15px;_position:absolute;_bottom:auto;_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));_margin-bottom:15px;}
/*���IE6�²����� position:fixed ������*/
#pinglun,#xiangguan,#gotop{width:54px;height:56px;background:url(../images/icon.png) no-repeat;display:block;}
#pinglun{background-position:0 0;}
#xiangguan{background-position:0 -59px;}
#gotop{background-position:0 -118px;}