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

Calling reveal() on the same target does work with config.origin as "top" or "left" [solved v3.2.0] #270

Closed
jlmakes opened this issue Jul 6, 2016 · 1 comment
Labels

Comments

@jlmakes
Copy link
Owner

jlmakes commented Jul 6, 2016

Recreating The Problem

config = {
  duration: 2000,
  distance: '1000px',
  origin: 'top'
}

window.sr = ScrollReveal(config)
sr.reveal('.box')
sr.reveal('.box')

After the first reveal, the distance for the CSS Translate X will be -1000 because of this bit in the _configure() method:

// Let’s make sure our our pixel distances are negative for top and left.
// e.g. origin = 'top' and distance = '25px' starts at `top: -25px` in CSS.
if (elem.config.origin === 'top' || elem.config.origin === 'left') {
  elem.config.distance = '-' + elem.config.distance
}

The problem is that the second time through, this bit of code will result in --1000...

And that’s just nonsense.

@jlmakes jlmakes added the Bug label Jul 6, 2016
@jlmakes jlmakes added this to the ScrollReveal v3.2.0 milestone Jul 6, 2016
@jlmakes jlmakes changed the title Calling reveal() on the same target always uses library default config Calling reveal() on the same target does work with config.origin as "top" or "left" Jul 6, 2016
@jlmakes
Copy link
Owner Author

jlmakes commented Jul 6, 2016

lol, nice distance bro...

screen shot 2016-07-08 at 1 15 32 pm

Since the config.distance is a string (in order to support various CSS units), it’s unfortunately not as simple as just using Math.abs(elem.config.distance) * -1.

Instead, that same logic must be expressed using a regex to check if the config.distance starts with -, and remove or add - as necessary.

Also, I’m going to move the offending lines out of the _configure() method and into the _generateTransform() method where the distance value is actually used.

Example:

var config = elem.config
var cssDistance

// Let’s make sure our our pixel distances are negative for top and left.
// e.g. origin = 'top' and distance = '25px' starts at `top: -25px` in CSS.
if (config.origin === 'top' || config.origin === 'left') {
  cssDistance = /^-/.test(config.distance)
    ? config.distance.substr(1)
    : '-' + config.distance
}

@jlmakes jlmakes closed this as completed in 7e4649e Jul 8, 2016
@jlmakes jlmakes changed the title Calling reveal() on the same target does work with config.origin as "top" or "left" Calling reveal() on the same target does work with config.origin as "top" or "left" [solved v3.2.0] Sep 16, 2016
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

1 participant