用jquery写的回到顶部的操作
问题描述
页面中有一个div,当点击时,页面的滚动条自动回到顶部,也就是回到页面顶部。采用的思路就是通过定时器或者animate的方式。
先看第一种方法(定时器)
采用这种方法出现了bug,研究了一会发现问题所在,先看错误代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>03_回到顶部</title>
<style>
#to_top {
width: 30px;
height: 40px;
font: 14px/20px arial;
text-align: center;
background: #06c;
position: fixed;
cursor: pointer;
color: #fff;
left: 1050px;
top: 500px;
}
</style>
</head>
<body style="height: 2000px;">
<div id="to_top">返回顶部</div>
<script type="text/javascript" src="../js/jquery-1.10.1.js"></script>
<script type="text/javascript">
$