Scroll Up

Tool to let you scroll to the top of the page

当前为 2017-08-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Scroll Up
  3. // @namespace
  4. // @version 0.1
  5. // @description Tool to let you scroll to the top of the page
  6. // @author A Meaty Alt
  7. // @exclude https://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=21
  8. // @include /fairview.deadfrontier.com/
  9. // @require http://code.jquery.com/jquery-1.12.4.min.js
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var scroller = document.createElement("img");
  16. scroller.src = "https://puu.sh/xluRH/c8dd354a59.png";
  17. scroller.id = "scroller";
  18. scroller.style.opacity = 0.3;
  19. scroller.style.position = "fixed";
  20. scroller.style.zIndex = 99;
  21. scroller.style.cursor = "pointer";
  22. scroller.style.bottom = "30px";
  23. scroller.style.right = "20px";
  24. scroller.height = 100;
  25. scroller.width = 100;
  26. function defineOnClickEvent(){
  27. $(scroller).click(function() {
  28. $("html, body").animate({ scrollTop: 0 }, "slow");
  29. return false;
  30. });
  31. }
  32. function defineOnScrollEvent(){
  33. $(document).scroll(function() {
  34. if($(window).scrollTop() === 0) {
  35. $("#scroller").css("opacity", 0.3);
  36. }
  37. else
  38. $("#scroller").css("opacity", 1);
  39. });
  40. }
  41. defineOnScrollEvent();
  42. defineOnClickEvent();
  43. document.getElementsByTagName("body")[0].appendChild(scroller);
  44. })();