Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defining multiple rellax classes via js #218

Open
joehdevwp opened this issue Nov 21, 2020 · 2 comments
Open

defining multiple rellax classes via js #218

joehdevwp opened this issue Nov 21, 2020 · 2 comments

Comments

@joehdevwp
Copy link

joehdevwp commented Nov 21, 2020

I am trying to globally define many different rellax classes rather than use html data attributes, so that I can change them globally. However due to the need to destroy for mobile and refresh, I am hoping to use one variable and create an array of many classes each with different speed settings, like this:

let rellax = [new Rellax ('.one.has-parallax', { speed: 7, center: true, wrapper: null, round: true, vertical: true, horizontal: false, })], [new Rellax ('.two.has-parallax', { speed: 2, center: true, wrapper: null, round: true, vertical: true, horizontal: false, })];

But this breaks it. Any help? thank you.

Or maybe someone can suggest a smarter way to do this.

@zangab
Copy link

zangab commented Dec 8, 2020

if you would do it with the html data attributes, you would save some bytes because you don't bloat the js unneccessarily.
but i guess i would define a config array with objects and then loop over all:

const relaxConfigs = [
  {
    selector: '.one.has-parallax',
    options: {
      speed: 7,
      center: true,
      ...
    },
  },
  {
    selector: '.two.has-parallax',
    options: {
      speed: 2,
      center: true,
      ...
    },
];

relaxConfigs.forEach(config => new Rellax(config.selector, config.options));

@joehdevwp
Copy link
Author

thank you @zangab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants