Back To Top

click the arrow-up pic to jump to the top of page.

目前为 2017-05-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Back To Top
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description click the arrow-up pic to jump to the top of page.
  6. // @author kilin
  7. // @include *
  8. // @match *
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. window.onload = function(){
  15. var aNode = document.createElement('a');
  16. aNode.href = 'javascript:;';
  17. aNode.id = 'click-to-top';
  18. aNode.title = 'Click it to go to the top';
  19. var css = '#click-to-top{ position: fixed; right: 5%; bottom: 20%; opacity: 0.2; z-index: 99; } #click-to-top:hover{ position: fixed; right: 5%; bottom: 20%; opacity: 1; z-index: 99; }';
  20. //图片相关
  21. var img = document.createElement('img');
  22. img.src = 'https://ooo.0o0.ooo/2017/05/23/59245c636b321.png';
  23. img.style = 'width: 30px; height: 30px;';
  24. //样式相关
  25. var style = document.createElement('style');
  26. if (style.styleSheet) {
  27. style.styleSheet.cssText = css;
  28. } else {
  29. style.appendChild(document.createTextNode(css));
  30. }
  31. document.getElementsByTagName('head')[0].appendChild(style);
  32. aNode.append(img);
  33. aNode.addEventListener('click', function(){document.documentElement.scrollIntoView();}, false);
  34. var body = document.querySelector('body');
  35. body.append(aNode);
  36. };
  37. })();