滚动到页面顶部,无需刷新/重新加载该页面

时间:2013-12-15 17:05:23

标签: javascript jquery html

我正在开发一个移动网站。该网站主要在Opera mini和UCbrowser中查看。我已将滚动添加到顶部按钮

<input type="button" name="scroll to top" onclick="scroll(0,0)"/>

但点击它重新加载然后转到顶部。有时,它不起作用..

详情请参阅opera mini和ucbrowser中的feinix.org/mevents.php

在opera mini中查看m.facebook.com他们添加了[↑] Top。如果有人发布我背后的代码

,那就太好了

2 个答案:

答案 0 :(得分:3)

使用Jquery

 $("html, body").animate({
    scrollTop: 0
}, 200);    

或使用像这样的简单Html锚点

 //Add this to your top of your page
 <a id="tips"></a>

 //Show this as your button with css
 <a href="#tips">Scroll to top</a>

答案 1 :(得分:0)

$("a[href='#top']").click(function() {
  $("html, body").animate({ scrollTop: 0 }, "slow");
  return false;
});
相关问题