<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>滚动事件</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<style>
img{
position:fixed;
top:640px;
left: 1200px;
display:none;
}
#box{
width:1000px;
height:1200px;
margin:0 auto;
border:1px solid red;
overflow:hidden;
}
</style>
<script>
/*
$(obj).position 获取定位的位置
$(obj).scrollTop(0)
$(obj).animate({},时间)
$(window).scroll(function(){
//窗口的滚动事件
});
*/
$(function(){
$(window).scroll(function(){
var value=$('body,html').scrollTop();
if(value>300){
$('img').fadeIn(300);
}else{
$('img').fadeOut(300);
}
});
$('img').click(function(){
$('body,html').animate({'scrollTop':0},'slow')
})
})
</script>
</head>
<body>
<div id="box"></div>
<img src="images/a1.png" alt="箭头">
</body>
</html>