Last active
January 18, 2019 15:01
-
-
Save markhowellsmead/6c3414386ab91ffc74ae994927766772 to your computer and use it in GitHub Desktop.
Say Hello: Carousel using Flickity, Timber and Twig, with custom cross-fade effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.flickity { | |
&--fade { | |
.flickity-slider { | |
transform: none !important; | |
} | |
.flickity-cell { | |
@include transition(all, slower); | |
left: 0 !important; | |
opacity: 0; | |
z-index: -1; | |
} | |
.flickity-cell.is-selected { | |
opacity: 1; | |
z-index: 0 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use SayHello\Theme\Vendor\LazyImage; | |
foreach ($context['post']->carousel['images'] as &$image) { | |
$image_object = new LazyImage($image, 'carousel_full'); | |
$image['lazyimage'] = $image_object->get_image(true); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if post.carousel.images is not empty %} | |
<div class="c-carousel"> | |
<div class="c-carousel__entries flickity--fade" data-carousel="fade"> | |
{% for slide in post.carousel.images %} | |
<div class="c-carousel__entry flickity-cell"> | |
{{ slide.lazyimage }} | |
</div> | |
{% endfor %} | |
</div> | |
</div> | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$('[data-carousel="fade"]').flickity({ | |
autoPlay: 5000, | |
cellSelector: '.flickity-cell', | |
draggable: false, | |
pageDots: false, | |
prevNextButtons: false | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment