nk-o / jarallax

Parallax scrolling for modern browsers
https://jarallax.nkdev.info
MIT License
1.39k stars 214 forks source link

Unable to override jQuery defaults with data attributes - since it works partially, it's a BUG, not a FR #214

Closed hidegh closed 1 year ago

hidegh commented 1 year ago

Issue description:

Using some default setup:

$('.jarallax').jarallax({
  speed: 0.2,
});

Which then locally I'd like to override:

          <div class="h-100 w-100 jarallax" data-jarallax data-type="scale" data-speed="-1" data-img-position="0% 50%">
            <img class="jarallax-img" src="/assets/bg/team/pexels-fauxels-3184355.jpg">
          </div>

I'd always expect the data-attributes (local to the given element) to override the generic jQuery selector values, if provided.

While the data-img-position is applied, the data-speed it totally ignores.

Version used:

2.0.4

Code to reproduce the issue (HTML blocks + JavaScript initialization)

See Issue desc.

nk-o commented 1 year ago

Data attributes should not override attributes provided in jQuery / JS calls. The order is defined here: https://github.com/nk-o/jarallax/blob/e38fc74e3bf11f3d6c5d3fabaff4f00f206b0238/src/core.js#L162

  1. Jarallax defaults
  2. Data attributes
  3. User's attributes (provided from jQuery / JS calls)