Smooth Scroll

Configurable smooth scroll with optional motion blur. Uses requestAnimationFrame (like V-Sync).

These are versions of this script where the code was updated. Show all versions.

  • v3.3 2025-04-13

    Smooth Scroll Changelog: v2.4 -> v3.3 - "The Big Refactor & Glow-Up" ✨

    Alright folks, big jump from v2.4! This wasn't just dusting off the cobwebs; it's more like a full engine swap and a new paint job. Here's the scoop on what changed:

    ✨ New Stuff & Major Goodies:

    1. Motion Blur (Optional Bling!): cfg.mBlur is here! If you turn it on, the page gets a subtle (or not-so-subtle, depending on cfg.mBlurInt) blur effect while scrolling fast. Looks slick, but might cost a tiny bit of performance on older machines. Off by default for max speed.
    2. Smarter Acceleration: Remember scrollAcceleration? It's been replaced with a more responsive system (cfg.accDelFct, cfg.accMaxMult). Now, quick consecutive scrolls build up a multiplier, making fast flicks feel way more punchy, up to a configurable limit. Feels more natural.
    3. VSync-Style Animation: Ditched the old refresh rate calculation (targetRefreshRate, requestAnimationFrameUpdate). We're now using pure requestAnimationFrame for the animation loop (_animStep). This means the animation timing is directly tied to your display's refresh rate – smoother, less guesswork, and generally the modern standard.

    🚀 Improvements & Refactors (Under the Hood):

    1. Core Animation Logic Overhaul: The entire scrolling calculation is simpler and based on a damping factor (1 - cfg.smth). Instead of complex time/ratio math, it's now just "move X% closer to the target each frame". More predictable, easier to tune.
    2. Better Target Finding (_getTgt): The logic for finding which element to scroll (the whole page? that nested div?) is more robust. It uses composedPath and directly checks scrollable dimensions and overflow styles, handling edge cases better than the old isScrollable/canScroll/hasScrollbar combo.
    3. Simplified State (stMap): No more juggling subPixelOffset and pixelScrollAmount. Each scrolling element now has a simple state object in a WeakMap holding its target (tgtY), current animated position (curY), animation ID, timestamp for acceleration (ts), and current acceleration multiplier (mult). Cleaner!
    4. Modern Structure (IIFE): Wrapped the whole thing in an IIFE (Immediately Invoked Function Expression). Less global pollution compared to the old SmoothScroll object approach. Functions are mostly internal now (_ prefix).
    5. Event Handling Tweaks: Now uses capture: true for listeners to grab events early. Explicitly non-passive (passive: false) for the wheel event to reliably preventDefault(). Also added touchstart listener to cancel animation on touch devices.
    6. Performance Focus: By simplifying the animation math and state, and relying directly on requestAnimationFrame, the core loop should be lighter. Removed the need for refresh rate calculation overhead.

    ⚙️ Config Changes (Out with the Old, In with the New):

    • Gone: scrollSmoothness, scrollAcceleration, debugMode, targetRefreshRate, maxRefreshRate, minRefreshRate, animationDuration, passiveEventListeners.
    • New:
      • smth: The smoothness factor (0 to 1, higher is smoother, opposite of old scrollSmoothness). Replaces scrollSmoothness.
      • stpMult: A simple overall multiplier for scroll distance.
      • accDelFct, accMaxMult: Control the new acceleration system. Replace scrollAcceleration.
      • thrsh: How close (in pixels) the scroll needs to be to the target before stopping. Replaces scrollThreshold conceptually.
      • lnHt: Default height (in pixels) for deltaMode === 1 (scroll by lines).
      • mBlur, mBlurInt: Toggle and control the motion blur intensity.
      • dbg: Simple true/false toggle for debug console logs.

    🗑️ Removed:

    • The complex sub-pixel offset tracking logic. We round to the nearest pixel now.
    • Dynamic refresh rate calculations and the associated min/max limits.
    • The SmoothScroll global object and its public start/stop methods (it's all internal now).
    • Browser fallbacks/polyfills (requestAnimationFrame, String.prototype.encamel) - assuming modern browser support.

    TL;DR:

    Version 3.3 is a significant rewrite focusing on smoother animation via requestAnimationFrame, a better acceleration feel, optional motion blur, more reliable target finding, and cleaner, modern code. Configuration is different, so check the new cfg object! Should feel better overall. Enjoy the scroll! 🚀

  • v2.4 2025-01-29

    Changelog

    Version 2.4

    • Major Refactor: Completely restructured the codebase for better organization and readability.
    • Settings Object: Introduced a SmoothScroll.settings object to easily configure scroll behavior.
    • WeakMap for State: Utilized WeakMap to store per-element scrolling data, preventing memory leaks.
    • Animation Duration: Added animationDuration to limit the maximum time for a smooth scroll animation.
    • Scroll Threshold: Added scrollThreshold to prevent animation on small scroll events.
    • Passive Event Listeners Option: Added a setting (passiveEventListeners) to allow users to choose if they want to use passive event listeners or not.
    • Error Handling in Style Retrieval: Added error handling when fetching style properties.
    • String.encamel Polyfill: Added a polyfill for older browsers missing the String.encamel method.
    • Code Formatting: Improved code formatting, code comments for better readability.
    • Version Update: Updated to version 2.4
    • Grant Update: Added @grant none since the script doesn't use any GM functions.
  • v2.3 2024-11-22

    Version 2.3

    • Added scroll pattern analysis for better device detection
    • Improved scroll physics and acceleration curves
    • Fixed up/down jitter issues
    • Enhanced subpixel accuracy
    • Added directional scroll handling
    • Fine-tuned performance parameters
  • v2.1 2024-11-22

    Smooth Scroll Minor Update

    Changelog (v2.1)

    Added

    • Support for Touchpad.
    • Added handlers for gesture events.
    • Added progressive momentum based on consecutive scroll events.
    • The script now automatically adjusts its behavior based on whether it detects touchpad or mouse wheel input
    • Provides smoother, more natural feeling scrolling for touchpad users

    Enhanced

    • Prevents default gesture behavior that might interfere with smooth scrolling
    • Adjusted smoothness calculation for touchpad input
  • v2.0 2024-11-18

    Enhanced Smooth Scroll Documentation

    Changelog (v2.0)

    Added

    • Class-based architecture for better code organization and maintainability
    • WeakMap-based state management to prevent memory leaks
    • Touch device support for mobile compatibility
    • Visibility change detection to cleanup scrolling when tab is hidden
    • Debug mode for easier troubleshooting
    • Configurable settings object for easy customization
    • Support for nested scrollable elements
    • Text selection detection to prevent scroll interference
    • Proper handling of different scroll modes (pixel, line, page)
    • Error recovery system for failed scroll attempts
    • Frame rate optimization with configurable limits
    • Subpixel scrolling accumulation for smoother motion

    Changed

    • Completely refactored code structure for better maintainability
    • Improved scroll animation algorithm for smoother motion
    • Enhanced scroll target detection logic
    • Better event listener management
    • More efficient frame rate calculation
    • Improved cross-browser compatibility
    • Better handling of scroll acceleration

    Fixed

    • Memory leaks from unbounded scroll animations
    • Scroll lockups on rapid direction changes
    • Nested scrollable elements conflicts
    • Cross-browser compatibility issues
    • Frame rate inconsistencies
    • Subpixel rounding errors
    • Event listener cleanup

    Removed

    • Global variable pollution
    • Redundant scroll calculations
    • Unnecessary DOM traversal
    • Legacy browser workarounds
    • Unused utility functions
  • v1.4 2024-07-28

    Smooth Scroll Function Changelog

    Version 1.4

    Enhancements and Fixes

    • Fixed Calculation Issues:

      • Improved calculations for smooth scrolling, ensuring consistent behavior across different pages.
      • Adjusted the logic for ScrollPixels and ScrollSubpixels to ensure proper handling and calculation.
    • Improved Scroll Handling:

      • Ensured the script properly handles different scrolling behaviors on various websites.
      • Added checks to handle cases where scrolling might get stuck.
    • Handled Edge Cases:

      • Added additional checks in CanScroll and HasScrollbar to handle edge cases.
      • Enhanced logic to ensure smooth scrolling even on pages with unusual scrolling behaviors.
    • Performance Improvements:

      • Optimized performance by refining the RequestAnimationUpdate function.
      • Ensured better frame rate calculations to maintain smooth animations.
    • Error Handling:

      • Added error handling mechanisms to prevent the script from breaking on certain pages.
      • Ensured the script fails gracefully when encountering unexpected scenarios.
    • General Code Cleanup:

      • Cleaned up and organized the code for better readability and maintainability.
      • Removed redundant code and improved comments for clarity.

    Known Issues

    • Compatibility:

      • The script may still encounter issues on websites with highly customized scrolling behaviors.
      • Further testing and adjustments may be required for specific edge cases.
    • Performance on Low-End Devices:

      • While performance improvements have been made, low-end devices may still experience some lag during smooth scrolling.
  • v1.3 2024-07-23