Software Alternatives & Reviews

How to detect scroll direction in vanilla JavaScript (to make a goofy logo animation)

Underscore.js Lo-Dash CodePen
  1. Underscore is a utility-belt library for JavaScript that provides a lot of the functional...
    Pricing:
    • Open Source
    /* Source: https://underscorejs.org/underscore-esm.js During a given window of time. Normally, the throttled function will run As much as it can, without ever going more than once per `wait` duration; But if you'd like to disable the execution on the leading edge, pass `{leading: false}`. To disable execution on the trailing edge, ditto. */ Function throttle(func, wait, options) { var timeout, context, args, result; var previous = 0; if (!options) options = {}; var later = function () { previous = options.leading === false ? 0 : Date.now(); timeout = null; result = func.apply(context, args); if (!timeout) context = args = null; }; var throttled = function () { var _now = Date.now(); if (!previous && options.leading === false) previous = _now; var remaining = wait - (_now - previous); context = this; args = arguments; if (remaining <= 0 || remaining > wait) { if (timeout) { clearTimeout(timeout); timeout = null; } previous = _now; result = func.apply(context, args); if (!timeout) context = args = null; } else if (!timeout && options.trailing !== false) { timeout = setTimeout(later, remaining); } return result; }; throttled.cancel = function () { clearTimeout(timeout); previous = 0; timeout = context = args = null; }; return throttled; }.

    #Development Tools #Javascript UI Libraries #JavaScript Framework 19 social mentions

  2. Lo-Dash is a drop-in replacement for Underscore.
    Pricing:
    • Open Source
    Lodash and underscore are 2 popular utility libraries.

    #Development Tools #Javascript UI Libraries #JavaScript Framework 85 social mentions

  3. A front end web development playground.
    See the Pen Detect scroll direction (throttling) by Rob (@robjoeol) on CodePen.

    #Text Editors #Programming #Code Collaboration 484 social mentions

Discuss: How to detect scroll direction in vanilla JavaScript (to make a goofy logo animation)

Log in or Post with