lazyScroller

Keep your hand free from scroll button.

当前为 2015-01-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name lazyScroller
  3. // @version 1.0
  4. // @description Keep your hand free from scroll button.
  5. // @namespace idmresettrial
  6. // @author idmresettrial
  7. // @run-at document-end
  8. // @grant none
  9.  
  10. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  11.  
  12. // Website list
  13.  
  14. // @match *://*/*
  15.  
  16. // End list
  17.  
  18.  
  19. // ==/UserScript==
  20.  
  21. // Do not run on frames or iframes
  22. if (window.top !== window.self) {
  23. return;
  24. }
  25.  
  26. red = "#f84848"; green = "#7abf16"; blue = "#3e68b3";
  27. color = blue;
  28.  
  29. transparent = 0.5;
  30.  
  31. distance = $(window).height()-50;
  32. duration = 250;
  33.  
  34. wait = 500;
  35. pause = 1000;
  36. var repeat;
  37.  
  38. direct = "lazySleep";
  39.  
  40. lazyScroller = '<div id="lazyScroller"><div class="lazyButton" id="lazyUp">↑</div><div class="lazyButton" id="lazyDown">↓</div></div>';
  41.  
  42. $("body").append(lazyScroller);
  43. $("#lazyScroller").css({"cursor":"default", "position":"fixed", "top":"-100px", "left":"-100px", "margin":"10px", "z-index":"999"});
  44. $(".lazyButton").css({"margin":"2px", "width":"20px", "height":"20px", "font-family":"calibri", "font-size":"12px", "line-height":"20px", "text-align":"center", "background":color, "color":"#FFFFFF"});
  45. $(".lazyButton").fadeTo(0, transparent);
  46.  
  47. $(window).mousemove(function(e) {
  48. if (Math.abs(parseInt($("#lazyScroller").css("left"))-e.clientX)>50 || Math.abs(parseInt($("#lazyScroller").css("top"))-e.clientY)>100) {
  49. $("#lazyScroller").css({"left":e.clientX, "top":e.clientY, "display":"none"});
  50. } else {
  51. $("#lazyScroller").slideDown();
  52. }
  53. });
  54.  
  55. $(window).scroll(function() {
  56. if ($(window).scrollTop() === 0) {
  57. $("#lazyUp").html("→");
  58. } else if ($(window).scrollTop() === ($(document).height()-$(window).height())) {
  59. $("#lazyDown").html("←");
  60. } else {
  61. $("#lazyUp").html("↑");
  62. $("#lazyDown").html("↓");
  63. }
  64. });
  65.  
  66. $("#lazyScroller .lazyButton").mouseover(function() {
  67. direct = $(this).attr("id");
  68. $(this).fadeTo(500, 1);
  69. repeat = setTimeout(function() {go();},wait);
  70. });
  71.  
  72. $("#lazyScroller .lazyButton").mouseout(function() {
  73. direct = "lazySleep";
  74. $(this).fadeTo(500, transparent);
  75. clearTimeout(repeat);
  76. });
  77.  
  78. $("#lazyScroller #lazyUp").click(function() {
  79. if ($(window).scrollTop() === 0) {
  80. direct = "lazyNext";
  81. } else {
  82. direct = "lazyTop";
  83. }
  84. go();
  85. });
  86.  
  87. $("#lazyScroller #lazyDown").click(function() {
  88. if ($(window).scrollTop() === ($(document).height()-$(window).height())) {
  89. direct = "lazyBack";
  90. } else {
  91. direct = "lazyBottom";
  92. }
  93. go();
  94. });
  95.  
  96. function go()
  97. {
  98. if (direct === "lazyUp") {
  99. $("html, body").animate({scrollTop: ($(window).scrollTop()-distance)}, duration);
  100. console.log($(window).scrollTop());
  101. repeat = setTimeout(function() {go();},duration+pause);
  102. } else if (direct === "lazyDown") {
  103. $("html, body").animate({scrollTop: ($(window).scrollTop()+distance)}, duration);
  104. repeat = setTimeout(function() {go();},duration+pause);
  105. } else if (direct === "lazyTop") {
  106. $("html, body").animate({scrollTop: 0},duration);
  107. } else if (direct === "lazyBottom") {
  108. $("html, body").animate({scrollTop: ($(document).height()-$(window).height())},duration);
  109. } else if (direct === "lazyNext") {
  110. history.go(+1);
  111. } else if (direct === "lazyBack") {
  112. history.go(-1);
  113. }
  114. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址