<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>滑动条</title>
<style>
.top{
width: 50px;
height:50px;
display: block;
background: #888;
color: #fff;
text-align: center;
font-size: 30px;
line-height: 50px;
/*text-decoration: none; 下划线的去掉方式*/
position: fixed;
right: 50px;
bottom: 50px;
display: none;
}
.top:hover{
background: #093;
}
</style>
<script src="./js/jquery-1.11.3.js" type="application/javascript"></script>
<!-- //需要1.11.3以上的版本支持-->
<script type="application/javascript">
$(function()
{
$(window).scroll(function(){
var t = $(this).scrollTop();
if(t>200){
$(".top").stop().fadeIn();
}else{
$(".top").stop().fadeOut();
}
// document.title = t;
});
//body 支持 webkit内核的浏览器
//火狐和IE需要添加 html
$(".top").click(function(){
$("body,html").stop().animate({scrollTop:0},300);
})
})
</script>
</head>
<body>
<a href="javascript:;" class="top" > 顶 </a>
<script>
for(var i=0; i<100;i++)
{
document.write("<h1>"+i+"</h1>");
}
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>滑动条</title>
<style>
.top{
width: 50px;
height:50px;
display: block;
background: #888;
color: #fff;
text-align: center;
font-size: 30px;
line-height: 50px;
/*text-decoration: none; 下划线的去掉方式*/
position: fixed;
right: 50px;
bottom: 50px;
display: none;
}
.top:hover{
background: #093;
}
</style>
<script src="./js/jquery-1.11.3.js" type="application/javascript"></script>
<!-- //需要1.11.3以上的版本支持-->
<script type="application/javascript">
$(function()
{
$(window).scroll(function(){
var t = $(this).scrollTop();
if(t>200){
$(".top").stop().fadeIn();
}else{
$(".top").stop().fadeOut();
}
// document.title = t;
});
//body 支持 webkit内核的浏览器
//火狐和IE需要添加 html
$(".top").click(function(){
$("body,html").stop().animate({scrollTop:0},300);
})
})
</script>
</head>
<body>
<a href="javascript:;" class="top" > 顶 </a>
<script>
for(var i=0; i<100;i++)
{
document.write("<h1>"+i+"</h1>");
}
</script>
</body>
</html>