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

Reset only when element is completely outside viewport #274

Closed
tofuness opened this issue Jul 16, 2016 · 2 comments
Closed

Reset only when element is completely outside viewport #274

tofuness opened this issue Jul 16, 2016 · 2 comments
Labels

Comments

@tofuness
Copy link

tofuness commented Jul 16, 2016

Running ScrollRreveal 3.2.0 on Chrome 51 (Windows 10)

I would love some guidance on how I can have viewFactor at 0.7 but only trigger reset after the element is completely outside the viewport.

Thanks!

@jlmakes
Copy link
Owner

jlmakes commented Jul 17, 2016

I put together a demo for you

Note: If you scroll up immediately after a reset triggers, there can be a bit of delay before the reveal triggers again, depending on your settings. When #273 is implemented, this delay could be removed by using the proposed beforeReset callback instead of afterReset.

ES6 Example (Terse):

window.sr = ScrollReveal()

const minVFactor = 0.0
const maxVFactor = 0.3

sr.reveal('.foo', {
  reset: true,
  viewFactor: maxVFactor,
  afterReveal: (el) => sr.reveal(el, { viewFactor: minVFactor }),
  afterReset: (el) => sr.reveal(el, { viewFactor: maxVFactor })
})

ES5 Example (Explicit):

window.sr = ScrollReveal();

var minVFactor = 0.0;
var maxVFactor = 0.3;

sr.reveal('.foo', {
  reset: true,
  viewFactor: maxVFactor,
  afterReveal: setMinVFactor,
  afterReset: setMaxVFactor
});

console.log("vFactor initialized as: " + maxVFactor);

// ScrollReveal callbacks are passed
// the dom element, so it’s easy to
// pass this to our setVFactor() method
// which re-reveals that element with
// the new configuration.

function setVFactor (el, vf) {
  sr.reveal(el, { viewFactor: vf });
}

// And the callbacks themselves...

function setMinVFactor (el) {
  setVFactor(el, minVFactor);
  console.log("vFactor set to: " + minVFactor);
}

function setMaxVFactor (el) {
  setVFactor(el, maxVFactor);
  console.log("vFactor set to: " + maxVFactor);
}

@tofuness
Copy link
Author

Thank you so much @jlmakes ! Closing this issue.

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

No branches or pull requests

2 participants