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

How can I change reveal settings based on screen width? #172

Closed
jj2020driver opened this issue Sep 3, 2015 · 2 comments
Closed

How can I change reveal settings based on screen width? #172

jj2020driver opened this issue Sep 3, 2015 · 2 comments
Labels

Comments

@jj2020driver
Copy link

Hello!

Do you think it is necessary/possible to implement width-dependent configuration?

For example, I have layout grid with 2 columns for wide screens and I set each even list item some delay to make left element in a row appear first and right element in a row appear next. However, my layout changes to 1 column, and there becomes no need to delay even items in my list.

Another words, it would be great to change behaviour
data-sr='enter left, move 24px, scale up 0%, delay 0.3s'
into
data-sr='enter left, move 24px, scale up 0%'
dynamically on page resize.

@jlmakes
Copy link
Owner

jlmakes commented Sep 12, 2015

Pseudo-code Example using ScrollReveal 3:

var config;
var small;
var large;
var checkWidth;

small = {
  delay : '0s',
  over  : '0.3s'
};

large = {
  delay : '0.3s',
  over  : '0.5s'
};

checkWidth = requestAnimationFrame(function() {
  // set the correct configuration object
  if ( window.innerWidth < 400 ) {
    config = small;
  } else {
    config = large;
  }
  // now create the reveal set
  if ( sr ) {
    sr.reveal('.selector', config );
  }
});

// instantiate ScrollReveal and perform our first width check
window.sr = ScrollReveal();
checkWidth();

window.addEventListener( 'resize', checkWidth );

This is just a demonstration—for production it would be smart to check the browser and use the correct requestAnimationFrame method name inside the event listener callback.

Hope this helps!

@jj2020driver
Copy link
Author

Ok thanks, great improvement!

@jlmakes jlmakes changed the title Support for media-queries-like options setting How can I change reveal settings based on screen width? Jan 13, 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

2 participants