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

onScroll method with force = true #13

Closed
hellor0bot opened this issue Jul 17, 2016 · 11 comments
Closed

onScroll method with force = true #13

hellor0bot opened this issue Jul 17, 2016 · 11 comments

Comments

@hellor0bot
Copy link

I'm trying to get parallax on slides inside a carousel.

Since there are slides that are out of viewport, Jarallax doesn't recalculate them on scroll. Hence I'm triggering carouselSlide.jarallax('onScroll'); after each slide change. But it doesn't effect slides outside the viewport.

Is there a way to force recalculation of slides outside the viewport with carouselSlide.jarallax('onScroll'); by enabling force: true somehow?

@hellor0bot
Copy link
Author

I think I found an even better solution.

It would be so great if we had a container option:

owlSlide.jarallax({
  container: '.carousel'
});

Sometimes, like in the situation with a carousel with hidden slides, there might be several parallax instances inside one container that are hidden but have to be recalculated onScroll.

We could check if the container is in the viewport, instead of checking each instance individually.

What do you think?

@nk-o
Copy link
Owner

nk-o commented Jul 18, 2016

Your solution will works for carousels with 1 visible item, but what if visible 2 or more items in the row? In this scenario will be calculated wrong image sizes.

@hellor0bot
Copy link
Author

@nk-o, it's exactly what I'm trying to explain:

If we had container parameter, then even if slides 1 and 5 are outside the viewport, parallax effect would still be applied to them.

@nk-o
Copy link
Owner

nk-o commented Jul 19, 2016

ah, I understand.
We should define not "container" option, but maybe custom isInViewport function to change check code.

@hellor0bot
Copy link
Author

I think an option would be better. It can be called something else, not container, like elementInViewport.

Then jarallax will check if the given element is in viewport and not the jarallax container itself.

What do you think?

@nk-o
Copy link
Owner

nk-o commented Jul 19, 2016

Only 1 thing. If we add this option elementInViewport: '.carousel'. Which of available carousels should use jarallax? On the page we can have more then 1 item with .carousel classname.

We can use jQuery / dom for elementInViewport option. I think this example will work for carousels:

$('.jarallax-for-carousel-item').each(function () {
   var $container = $(this).parents('.carousel:eq(0)');
   $(this).jarallax({
      elementInViewport: $container
   });
});

Today I will add this option and let you know.

@hellor0bot
Copy link
Author

@nk-o, great suggestion. Looking forward to it!

nk-o added a commit that referenced this issue Jul 19, 2016
@nk-o
Copy link
Owner

nk-o commented Jul 19, 2016

You can try new jarallax version

@hellor0bot
Copy link
Author

Thanks a lot, works like a charm!

Please correct the docs though: the option is elementInViewport, not isElement....

@robojiannis
Copy link

robojiannis commented Jun 11, 2018

how would this work with the data-attribute?
I'm using this slider (http://kenwheeler.github.io/slick/) but when moving the carousel, the next image is invisible until i scroll.

<div class='slick-gallery image' data-slick='{"slidesToShow": 1, "slidesToScroll": 1}'>
<?php			
foreach( $images as $image ): 
	echo "<div data-jarallax data-speed='0.2' data-element-in-viewport='.jarallax-img' data-img-size='cover' data-img-position='0 0' class='jarallax image'><img class='jarallax-img' src='" . $image['sizes']['large'] . "'/></div>";
endforeach;
?>				
</div> 

@umerata
Copy link

umerata commented Jul 17, 2019

@robojiannis Did you find out how to use it with data attributes

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

4 participants