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

Set wrapper to parent element #141

Open
pestbarn opened this issue Jan 10, 2019 · 11 comments
Open

Set wrapper to parent element #141

pestbarn opened this issue Jan 10, 2019 · 11 comments

Comments

@pestbarn
Copy link

pestbarn commented Jan 10, 2019

Would it be possible to add an option to set the wrapper to be the immediate parent? I'm working with a lot of generated content, where I don't have the possibility to specify the wrapper based on a class or id selector.

new Rellax('.rellax', { wrapper: this.parentElement })

// or on the element itself:
// data-parent-wrapper="true"

The above doesn't break anything, but obviously doesn't have any effect either. Could be a great addition 😃

@cheestudio
Copy link

I second this.

@dannyuk1982
Copy link

+1, if you have multiple background images, past the top one it's pretty tricky to use Rellax

@dannyuk1982
Copy link

Actually I've managed to get this to work

const rellaxin = document.querySelectorAll(".rellax");

rellaxin.forEach(el => {

  const rellax = new Rellax(el, {
    relativeToWrapper: true,
    wrapper: el.parentElement
  });

  window.addEventListener("scroll", () => { // fix to init
    rellax.refresh();
  });

});

@cheestudio
Copy link

That's gloriously simple and straightforward. I can't believe I've overlooked the relativeToWrapper option all this time!

@dannyuk1982
Copy link

dannyuk1982 commented Jan 22, 2020

Well I only just discovered this library 30 mins ago so benefit of fresh eyes, I was poking around the other issues and someone had done a PR with it, and seems to work! I'm not sure that relativeToWrapper even existed when this issue was created!

@cheestudio
Copy link

cheestudio commented Jan 22, 2020

Hm, it seems to have existed up to a few months prior to this issue being created:

#125

@dannyuk1982
Copy link

I got lucky then :) Hope it works for you too, I guess with a reference to the element you could always make a data-rellax-parent attribute to point to another class or id etc. if it's more complex than just referencing the immediate parent

@brandlewco
Copy link

Been having a similar issue but am worried about the evenr being triggered on scroll. is this how it runs traditionally, firing off a redraw for every pixel of scroll? seems like a lot more work.

@zangab
Copy link

zangab commented Dec 8, 2020

sorry, but this is just bad practice / performance:

window.addEventListener("scroll", () => { // fix to init
  rellax.refresh();
});

@dannyuk1982
Copy link

Agreed! It's far from ideal.

@pestbarn
Copy link
Author

pestbarn commented Dec 8, 2020

sorry, but this is just bad practice / performance:

window.addEventListener("scroll", () => { // fix to init
  rellax.refresh();
});

If you do this, you should definitely set up a debouncer.

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

5 participants