Smooth Scroll

Enables smooth page scrolling using JavaScript. Improved from an initial concept by Winceptor.

目前為 2025-01-29 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

作者
DXRK1E
評價
0 0 0
版本
2.4
建立日期
2024-07-23
更新日期
2025-01-29
尺寸
11.9 KB
授權條款
MIT
腳本執行於
所有網站

Smooth Scroll UserScript

Description:

This UserScript enhances your browsing experience by enabling smooth, animated scrolling on web pages. Unlike the default, jarring scroll behavior, this script provides a more fluid and visually pleasing way to navigate through content. It's designed to be customizable, allowing you to adjust the scrolling speed and smoothness to your personal preference.

Note: While this script is designed to be lightweight and performant, users on low-end PCs may experience some slight lag during scrolling. This is due to the increased processing required for the smooth animation.

Key Features:

  • Smooth Scrolling: Replaces the default jumpy scroll with a smooth animation.
  • Customizable: Allows you to adjust scroll smoothness and acceleration.
  • Intelligent Scrolling: Only animates when a significant scroll distance is detected.
  • Dynamic Refresh Rate: Automatically adjusts animation refresh rate for optimal performance.
  • Works Across Elements: Smooth scrolling works not just on the main page, but also on scrollable elements within the page.
  • Passive Event Listener (Optional): Allows users to configure if they want to use passive event listeners for enhanced performance.
  • Memory Efficient: Uses modern JavaScript techniques to avoid memory leaks.

How It Works:

This UserScript listens for mouse wheel (or trackpad) scroll events. When it detects one, it smoothly animates the scroll position of the page or scrollable element. It works by:

  1. Intercepting Scroll Events: Catches mouse wheel events, preventing the default scroll behavior.
  2. Calculating Scroll Amount: Determines how much to scroll based on the event.
  3. Animating the Scroll: Uses requestAnimationFrame to incrementally move the scroll position, creating a smooth effect.
  4. Dynamic Speed Adjustment: Adjusts scroll animation speed dynamically depending on the speed of the scroll and the desired smoothness.
  5. Stopping Scroll: Stops the animation when scrolling is no longer detected or the maximum animation duration is met.

Settings:

The script includes adjustable settings that you can modify in the script's code:

  • scrollSmoothness: Controls the animation smoothness. A value of 0 means the scroll will be very smooth and slow, 1 means the animation is going to be closer to the default speed. The best value is somewhere around 0.5.
  • scrollAcceleration: Controls how fast the scroll speed increases. Higher values cause a more aggressive acceleration, lower values less of an acceleration.
  • debugMode: Set to 1 to see console logs from the script; set to 0 to disable logging.
  • targetRefreshRate: Target animation refresh rate.
  • maxRefreshRate: Maximum refresh rate used for the animation.
  • minRefreshRate: Minimum refresh rate used for the animation.
  • animationDuration: Maximum duration (in milliseconds) for a scroll animation.
  • scrollThreshold: Minimum scroll distance required to trigger the smooth scrolling animation.
  • passiveEventListeners: If you want to use passive event listeners, set to true; false is the default value.

Installation:

  1. Install a UserScript manager (e.g., Tampermonkey, Violentmonkey).
  2. Copy the code for this script.
  3. In your UserScript manager, create a new script and paste the code.
  4. Save the script, and it will now automatically run on all websites.