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

Revealing large images causes odd behavior? #462

Closed
camsarmiento opened this issue Sep 25, 2018 · 14 comments
Closed

Revealing large images causes odd behavior? #462

camsarmiento opened this issue Sep 25, 2018 · 14 comments
Labels

Comments

@camsarmiento
Copy link

camsarmiento commented Sep 25, 2018

Hey I'm using scroll reveal v4 at this website http://camilomancilla.com.co/AGR.html but without reason stopped working, when scroll down shows the items for a while but then the items hide again as quick as I keep scrolling down, I've been searching about this bug but there isn't any case about this... Help me!!!

Environment

  • Operating System: Mac OS
  • Browser Version: Chrome 69.0.3497.100
  • ScrollReveal Version: v4

scroll reveal bug

@GarryKnimble
Copy link

GarryKnimble commented Sep 25, 2018

I added html, body {height:100%;} and it seems to work fine after that.

@jlmakes
Copy link
Owner

jlmakes commented Sep 28, 2018

ScrollReveal 4 adds body { height: 100%; } automatically; historically applying this style to html has not been necessary, but I'm curious if it was required in this case.

Did you solve this @camsarmiento ?

@camsarmiento
Copy link
Author

Not at all, I'be trying different stuff but it's been quite a mission, is there something else I can do ?

@GarryKnimble
Copy link

GarryKnimble commented Sep 29, 2018

Looking further into it, weirdly if the width of the window is smaller than a certain amount it stops working. However, bigger screen and it starts working again. Below is a gif of what happened to me. From my experimentation, it might be a styling issue. However, I will look further.

[need to fix link]

EDIT: After further investigation, it looks like it starts working when the window is resized width wise and not the css change. It seems to be only happening in webkit browsers. I'll keep experimenting. @jlmakes

@camsarmiento Have you tried viewing the webpage in a browser like Edge or Internet Explorer? It seems to work fine in those browsers.

EDIT2: I'm getting conflicting results, but it seems the only browser it doesn't work in is Chrome for me.

@twister65
Copy link

twister65 commented Sep 30, 2018

I had the same problem with my website, I called the sync function using the option.beforeReset callback to resolve it (with the option.reset as true).

For example :

sr.reveal('#search', {
  beforeReset: function(){
    sr.sync()
  },
  reset: true
});

re: https://scrollrevealjs.org/api/sync.html

@twister65
Copy link

twister65 commented Sep 30, 2018

With `option.reset` `true` ![without sync before reset](https://user-images.githubusercontent.com/26852967/46258361-9d388e00-c4c9-11e8-913e-1e77a5bd878a.gif)
With `option.reset` `true` and `option.beforeReset` `function(){ sr.sync(); }`

with sync before reset

@twister65
Copy link

Otherwise, replace :
https://github.com/scrollreveal/scrollreveal/blob/2f70956cca0a65afdd808d3036f3f111fd564862/dist/scrollreveal.js#L1043
by :
styles.push(element.styles.opacity.computed);
And replace :
https://github.com/scrollreveal/scrollreveal/blob/2f70956cca0a65afdd808d3036f3f111fd564862/dist/scrollreveal.js#L858
by :
styles.push(element.styles.opacity.computed);
in initialize and triggerReset functions

@jlmakes
Copy link
Owner

jlmakes commented Sep 30, 2018

I'm noticing in both examples, there are rather large images being revealed.

It's starting to sound like ScrollReveal is being initialized before these large images have finished loading. If that were true, then the element dimensions could be incorrect, making elements reveal/reset at unexpected times— and explain why calling sync() would fix things.

@camsarmiento try wrapping your ScrollReveal code in a load event handler, e.g:

window.addEventListener('load', function() {
  ScrollReveal().reveal('.items');
});

@twister65
Copy link

In my case, it is a slider (set of images) and it takes much time to be loaded than other elements. This issue occurs only when reset is triggered (reveal works fine).

@twister65
Copy link

twister65 commented Oct 2, 2018

Wrapping code for an article body :

window.addEventListener('load', function() {
  sr.reveal('.main_component', {
    origin: 'top',
    distance: '50px',
    duration: 1330,
    reset: false
  });
});
Result : the article has disappeared

agir pour la planete - avenir durable - google chrome 02_10_2018 17_38_58

Note : if option.reset is true then 👍

twister65 added a commit to twister65/joomspirit_99 that referenced this issue Oct 3, 2018
See jlmakes/scrollreveal#462
Update from ScrollReveal v4.0.0 to v4.0.4
@jlmakes
Copy link
Owner

jlmakes commented Oct 4, 2018

Any updates @camsarmiento @johnphilosopher ?

@GarryKnimble
Copy link

Any updates @camsarmiento @johnphilosopher ?

I can't really seem to come to a definitive conclusion as seemingly resizing the browser window in chrome fixes the problem, while it works properly in other browsers. I admittedly haven't tested much else after, but I'll look into it more.

@jlmakes
Copy link
Owner

jlmakes commented Oct 7, 2018

I really appreciate your help @johnphilosopher

I can't really seem to come to a definitive conclusion as seemingly resizing the browser window in chrome fixes the problem

There's enough evidence in this thread, that I'm almost certain the problem is that large images are passed to ScrollReveal before they have finished loading.

ScrollReveal caches element dimensions for faster scroll event handling, but these dimensions are updated on browser resize.

Element dimensions are essential to reveal logic, so it's important that large images be given time to finish loading and assume their proper dimensions. (This was why I suggested using ScrollReveal on large images inside a window load event callback.)

This whole situation can be avoided by:

  1. Applying height and width properties to images using HTML or CSS
  2. Revealing large images after they have loaded, e.g. inside a window load event callback

@jlmakes jlmakes closed this as completed Oct 7, 2018
@jlmakes jlmakes changed the title Scroll reveal not working correctly Revealing large images causes odd behavior? Oct 7, 2018
@saintplay
Copy link

I agree with @jlmakes, is the responsibility of the developer to be aware of these image loading inconsistencies. Other libraries like scroll-to-element that rely on element position will also fail, because of the same problem

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

5 participants