swissup/module-stickyfill

The most accurate sticky polyfill out in the wild for Magento 2

Installs: 253 424

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 8

Forks: 3

Open Issues: 0

Language:JavaScript

Type:magento2-module

1.2.2 2020-07-30 12:42 UTC

This package is auto-updated.

Last update: 2024-11-29 05:44:44 UTC


README

Stickyfill - is a Magento2 module that integrates Stickyfill library into Magento.

The module also provides additional features: it may add sticky-active class, when element is actually stuck at the moment.

Installation

cd <magento_root>
composer require swissup/module-stickyfill
bin/magento module:enable Swissup_Stickyfill
bin/magento setup:upgrade

Usage

Basic example:

require(['stickyfill'], function (Stickyfill) {
    Stickyfill.add(document.querySelectorAll('.sidebar'));
});

See all available methods at official site: https://github.com/wilddeer/stickyfill#api

Advanced example (works for dynamically added elements):

require([
    'Magento_Ui/js/lib/view/utils/async',
    'stickyfill'
], function ($, Stickyfill) {
    $.async('.sidebar', function (el) {
        Stickyfill.add(el);
    });
});

Additional features

Swissup_Stickyfill/js/sticky - is a proxy to stickyfill library that adds sticky-active class name when element is stuck. It has the following methods:

Basic usage:

require([
    'Swissup_Stickyfill/js/sticky'
], function (sticky) {
    sticky.add(document.querySelectorAll('.sidebar'))
});

Using with matchMedia library:

require([
    'matchMedia',
    'Swissup_Stickyfill/js/sticky'
], function (mediaCheck, sticky) {
    'use strict';

    var sidebar = document.querySelectorAll('.sidebar');

    mediaCheck({
        media: '(min-width: 768px)',
        entry: function () {
            sticky.add(sidebar);
        },
        exit: function () {
            sticky.remove(sidebar);
        }
    });
});