2013-12-15 144 views
0

我正在开发移动网站。该网站主要在Opera mini和UCbrowser中查看。我已经添加滚动到顶部按钮作为滚动到页面顶部,无需刷新/重新加载该页面

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

但这点击它重新加载,然后到顶部。有些时候,它不工作..

的细节去的Opera Mini及UC浏览器中的Opera Mini

视图m.facebook.com他们增加[↑]顶到feinix.org/mevents.php 。如果有人张贴在我身后说

+1

尝试'window.scrollTo(0,0这将是巨大的);'[我如何使用jQuery滚动到页面顶部?](http://stackoverflow.com/questions/1144805/how-do-i-scroll-to-the-top-of-the-page -with-jquery) – Satpal

+0

尝试'$(selector).scrollTop(0)' – Stiger

+0

尝试在scr之前设置preventDefault OLL(0,0)。像这样:'document.querySelector(“”).addEventListener(“click”,function(e){e.preventDefault(); window.scroll(0,0);});' – mqchen

回答

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> 
+0

+1。 – gvee

+1

谢谢,我个人喜欢jQuery,因为它给顺利的动画去顶部。 –

+0

感谢您的代码。它效果很好 – Kanmaniselvan

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