scrollWithMouseMove

鼠标在滚动条上移动滚动网页

  1. // ==UserScript==
  2. // @name scrollWithMouseMove
  3. // @namespace https://github.com/sakuyaa/gm_scripts
  4. // @description 鼠标在滚动条上移动滚动网页
  5. // @include *
  6. // @version 2022.11.28
  7. // @grant none
  8. // @note 修改自原脚本ScrollWithMouse.uc.js,来自Mozest.com社区
  9. // @note modify by sakuyaa
  10. // @run-at document-start
  11. // ==/UserScript==
  12. (function() {
  13. let scrolling = false; //处于滚动条位置
  14. let scrollStartY = -1; //移动起点高度
  15. let mouseScroll = event => {
  16. if (scrollStartY != -1) {
  17. //网页移动距离即为移动高度与网页可见区域高度的比例乘以网页正文全文高度
  18. document.documentElement.scrollTop += (event.screenY - scrollStartY) / document.documentElement.clientHeight * document.documentElement.scrollHeight;
  19. }
  20. scrollStartY = event.screenY; //储存下次移动起点高度
  21. }
  22.  
  23. document.addEventListener('mouseover', e => {
  24. if (!scrolling && e.clientX >= document.documentElement.clientWidth) { //处于滚动条位置
  25. scrolling = true;
  26. window.addEventListener('mousemove', mouseScroll, true)
  27. }
  28. });
  29. document.addEventListener('mouseout', e => { //移出滚动条
  30. if (scrolling) {
  31. scrolling = false;
  32. scrollStartY = -1;
  33. window.removeEventListener('mousemove', mouseScroll, true)
  34. }
  35. });
  36. })();

QingJ © 2025

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