以下是 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代码,悬浮漂浮,JS广告代码,JS特效代码" />
<meta name="description" content="此代码内容为jQuery火箭回到星空顶部效果,属于站长常用代码" />
<title>jQuery火箭回到星空顶部效果</title>
<link href="css/lrtk.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body style="height:3000px">
<!-- 代码 开始 -->
<div class="actGotop"><a href="javascript:;" title="Top"></a></div>
<script type="text/javascript">
$(function(){
$(window).scroll(function() {
if($(window).scrollTop() >= 100){ //向下滚动像素大于这个值时,即出现小火箭~
$('.actGotop').fadeIn(300); //火箭淡入的时间,越小出现的越快~
}else{
$('.actGotop').fadeOut(300); //火箭淡出的时间,越小消失的越快~
}
});
$('.actGotop').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); //火箭动画停留时间,越小消失的越快~
});
</script>
</body>
</html>
CSS代码(lrtk.css):
/* ����ͼ�� �Ѽ����� www.lanrentuku.com */
body{background:url(../images/bg.png);color:#FFF}
a{color:#FFF;}
.actGotop{position:fixed;_position:absolute;bottom:100px;right:50px;width:150px;height:195px;display:none;}
.actGotop a,.actGotop a:link{width:150px;height:195px;display:inline-block;background:url(../images/gotop.png) no-repeat;_background:url(../images/gotop.gif) no-repeat;outline:none;}
.actGotop a:hover{width:150px;height:195px;background:url(../images/gotopd.gif) no-repeat;outline:none;}