简体   繁体   中英

Top of Page Javascript Bookmarklet

Can anyone tell me how to turn

<a href="javascript:scroll(0,0)"> Top</a>

aka the Top of Page link into a Bookmarklet.

Not very knowledgeable with JavaScript and cannot get this into want I want it to be.

Or if I am using the wrong code, then can you fix it for me and turn it into the bookmarklet.

Create a bookmark with location:

javascript:void(function(){window.scroll(0,0)}())

Works in Firefox 3 and IE 7.

here is an article from my bookmarks .. its a simple and easy solution that I have been using for a long time now.

http://www.geeksww.com/tutorials/web_development/javascript/tips_and_tricks/javascript_go_to_top_of_page.php

hope this works

Another option ...

function scrollUp(){
  var offy;
  if(self.pageYOffset) {
        offy = self.pageYOffset;
  } else if(document.documentElement && document.documentElement.scrollTop){
        offy = document.documentElement.scrollTop;
  } else {
        offy = document.body.scrollTop;
  }

  if(offy <= 0) return;

  window.scrollBy(0, -50);
  setTimeout("scrollUp()", 10);

}

<a href="javascript: scrollUp();">Start Scroller!</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM