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

QingJ © 2025

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