Scroll Up

Tool to let you scroll to the top of the page

目前为 2017-08-30 提交的版本。查看 最新版本

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