1

I'm developing a mobile website. This website was mostly viewed in Opera mini and UCbrowser. I have added scroll to top button as

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

but this on click it reloads and then goes to the top. some times, it doesn't work..

for details go to feinix.org/mevents.php in opera mini and ucbrowser

view m.facebook.com in opera mini they have added [ ↑ ] Top. it would be great if someone post me the code behind that

Omar
  • 32,302
  • 9
  • 69
  • 112
Kanmaniselvan
  • 522
  • 1
  • 8
  • 23
  • 1
    try `window.scrollTo(0, 0);` [How do I scroll to the top of the page with jQuery?](http://stackoverflow.com/questions/1144805/how-do-i-scroll-to-the-top-of-the-page-with-jquery) – Satpal Dec 15 '13 at 17:07
  • try `$(selector).scrollTop(0)` – Stiger Dec 15 '13 at 17:09
  • try preventDefault before scroll(0,0). Like so: `document.querySelector("").addEventListener("click", function(e) { e.preventDefault(); window.scroll(0,0); });` – mqchen Dec 15 '13 at 17:10

2 Answers2

4

Using Jquery

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

or using simple Html Anchors like this

 //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>
Airy
  • 5,484
  • 7
  • 53
  • 78
0
$("a[href='#top']").click(function() {
  $("html, body").animate({ scrollTop: 0 }, "slow");
  return false;
});
m59
  • 43,214
  • 14
  • 119
  • 136
Vivekh
  • 4,141
  • 11
  • 57
  • 102