我有以下jQuery代码
$(document).ready(function () {
$('.navtoTop').click(function(){
$("html").scrollTop( $("#topofthePage").offset().top );
});
});
Run Code Online (Sandbox Code Playgroud)
其中'navtoTop'是按钮的类(类似'返回顶部'),它在页面的左下角有固定位置,'topofthePage'是<div>我页面最顶部的id .
我甚至试过这个
$('.navtoTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
Run Code Online (Sandbox Code Playgroud)
这是html代码
<body>
<div id="topofthePage"></div>
...
...
<img src="navtoTop.png" class="navtoTop">
</body>
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题,但这不起作用.有人会解释并给出一个好的解决方案吗?
如果需要,请向我询问代码的详细信息.