Scroll Up/Down

Tool to let you scroll to the top/bottom of the page

当前为 2017-09-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Scroll Up/Down
  3. // @version 1.10
  4. // @description Tool to let you scroll to the top/bottom 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. // @grant none
  11. // @namespace
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. var scrollerUp = document.createElement("img");
  17. scrollerUp.src = "https://puu.sh/xluRH/c8dd354a59.png";
  18. scrollerUp.id = "scrollerUp";
  19. scrollerUp.style.opacity = 0.3;
  20. scrollerUp.style.position = "fixed";
  21. scrollerUp.style.zIndex = 99;
  22. scrollerUp.style.cursor = "pointer";
  23. scrollerUp.style.bottom = "30px";
  24. scrollerUp.style.right = "10px";
  25. scrollerUp.height = 80;
  26. scrollerUp.width = 80;
  27. var scrollerDown = document.createElement("img");
  28. scrollerDown.src = "https://puu.sh/xsiqh/ed54ae27ab.png";
  29. scrollerDown.id = "scrollerDown";
  30. scrollerDown.style.opacity = 0.3;
  31. scrollerDown.style.position = "fixed";
  32. scrollerDown.style.zIndex = 99;
  33. scrollerDown.style.cursor = "pointer";
  34. scrollerDown.style.bottom = "30px";
  35. scrollerDown.style.right = "90px";
  36. scrollerDown.height = 80;
  37. scrollerDown.width = 80;
  38. function defineOnClickEvent(){
  39. $(scrollerUp).click(function() {
  40. $("html, body").animate({ scrollTop: 0 }, "slow");
  41. return false;
  42. });
  43. $(scrollerDown).click(function() {
  44. var bottom = $(document).height() - $(window).height();
  45. $("html, body").animate({ scrollTop: bottom }, "slow");
  46. return false;
  47. });
  48. }
  49. function defineOnScrollEvent(){
  50. $(document).scroll(function() {
  51. if($(window).scrollTop() === 0) {
  52. $(scrollerUp).css("opacity", 0.3);
  53. }
  54. else
  55. $(scrollerUp).css("opacity", 1);
  56. var bottom = $(document).height() - $(window).height();
  57. if($(window).scrollTop() === bottom){
  58. $(scrollerDown).css("opacity", 0.3);
  59. }
  60. else
  61. $(scrollerDown).css("opacity", 1);
  62. });
  63. }
  64. defineOnScrollEvent();
  65. defineOnClickEvent();
  66. $("body").append(scrollerUp);
  67. $("body").append(scrollerDown);
  68. })();