<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>js2</title>
<style>
.returnTop{
position:fixed;
width:50;
height:60px;
right:20px;
bottom:20px;
background-color:red;
color:white;
}
.hide{
display:none;
}
</style>
<body>
<div id='return_top' class='returnTop hide' οnclick='Go();'>返回顶部</div>
<div style='height:3000px;'></div>
<script src='js/jquery-1.8.2.js'></script>
<script src='js/oldboy.js'></script>
<script type='text/javascript'>
$(windw).scroll(function(){
var height = $(window).scrollTop();
if(height > 0){
$('#return_top').removeClass('hide')
}
else{
$('return_top').addClass('hide')
}
});
function Go(){
$(window).scrollTop(0);
}
</script>
</body>
</head>
</html>
==================方法2====================
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>js2</title>
<style>
.returnTop{
position:fixed;
width:50;
height:60px;
right:20px;
bottom:20px;
background-color:red;
color:white;
}
.hide{
display:none;
}
</style>
<body>
<div id='return_top' class='returnTop hide'>返回顶部</div>
<div style='height:3000px;'>asd</div>
<script src='js/jquery-1.8.2.js'></script>
<script src='js/oldboy.js'></script>
<script type='text/javascript'>
$(function(){
$('#return_top').click(function(){
$(window).scrollTop(0);
})
})
$(windw).scroll(function(){
var height = $(window).scrollTop();
if(height > 0){
$('#return_top').removeClass('hide')
}
else{
$('return_top').addClass('hide')
}
});
</script>
</body>
</head>
</html>
实现 “返回顶部”功能
最新推荐文章于 2024-04-18 16:21:11 发布