From our sponsor: Ready to show your plugin skills? Enter the Penpot Plugins Contest (Nov 15-Dec 15) to win cash prizes!
Today we’d like to share a simple decorative slideshow component with you. The idea behind this slideshow is to have an individual layout for each slide, accompanied by a distinct effect. The images of each slide is meant to have a decorative purpose which could be suitable for an article header; or, for example, an ornamental quotes slideshow within an article.
The animations for this slideshow are powered by anime.js by Julian Garnier. The images we use in the demos are from Unsplash.com, a great resource for free high-quality images.
The slideshow structure looks as follows:
<div class="slideshow">
<div class="slide slide--layout-1" data-layout="layout1">
<div class="slide-imgwrap">
<div class="slide__img"><div class="slide__img-inner" style="background-image: url(img/1.jpg);"></div></div>
<div class="slide__img"><div class="slide__img-inner" style="background-image: url(img/2.jpg);"></div></div>
<div class="slide__img"><div class="slide__img-inner" style="background-image: url(img/3.jpg);"></div></div>
</div>
<div class="slide__title">
<h3 class="slide__title-main">Now or Never</h3>
<p class="slide__title-sub">Our battered suitcases were piled on the sidewalk again; we had longer ways to go. But no matter, the road is life. <a href="#">Read more</a></p>
</div>
</div><!-- /slide -->
<div class="slide slide--layout-2" data-layout="layout2">
<!-- ... -->
</div>
<!-- ... -->
</div><!-- /slideshow -->
Each slide has the respective layout class and also a data-layout attribute that will help us define individual animations for each slide.
Tiny break: 📬 Want to stay up to date with frontend and trends in web design? Subscribe and get our Collective newsletter twice a tweek.
An example for the styles of a layout is the following:
/* Layout 1: 3 grid images */
.slide--layout-1 .slide__img {
position: absolute;
width: calc(50% - 1em);
}
.slide--layout-1 .slide__img:first-child {
left: 0.5em;
height: 100%;
}
.slide--layout-1 .slide__img:nth-child(n+2) {
left: calc(50% + 0.5em);
height: calc(50% - 0.5em);
}
.slide--layout-1 .slide__img:nth-child(3) {
top: calc(50% + 0.5em);
}
This layout can be achieved in many different ways; keep in mind that this is merely an example.
The animations for each layout are defined in our layout configuration. The structure is [layout name] : { out : {navigating out properties}, in : {navigating in properties} }. We can set different animations for the incoming slide and the disappearing one, where we can distinguish between whether the slide is the next or previous one. We use anime.js for the animations and you can find out more about the structure and how to use it in the GitHub repo.
The following is an example (first layout in the demo):
MLSlideshow.prototype.options = {
// Starting position.
startIdx : 0,
// Layout configuration.
// [layout name] : { out : {navigating out properties}, in : {navigating in properties} }
// For some properties we can have a "next" and "prev" behavior which can be different for the two - navigating out/in to the right or left.
// For the translationX/Y we can use percentage values (relative to the Slideshow).
layoutConfig : {
layout1 : {
out : {
translateX : {
next: '-100%',
prev: '100%'
},
rotateZ : {
next: function(el, index) {
return anime.random(-15, 0);
},
prev: function(el, index) {
return anime.random(0, 15);
}
},
opacity : 0,
duration: 1200,
easing : 'easeOutQuint',
itemsDelay : 80
},
in : {
resetProps : {
translateX : {
next: '100%',
prev: '-100%'
},
rotateZ : {
next: function(el, index) {
return anime.random(0, 15);
},
prev: function(el, index) {
return anime.random(-15, 0);
}
},
opacity : 0,
},
translateX : '0%',
rotateZ : 0,
opacity : 1,
duration: 700,
easing : 'easeOutQuint',
itemsDelay : 80
}
},
layout2 : { /* ... */ },
layout3 : { /* ... */ },
/* ... */
}
};
We hope you enjoy this little slideshow component and find it useful.
Browser Support:- ChromeSupported
- FirefoxSupported
- Internet ExplorerSupported from version 11
- SafariSupported from version 9
- OperaSupported
Please note that the last layout will not work in IE because the clip-path property is not supported.
Thanks a lot for the great article and demo. One thing I noticed, though, is that the rhomboid clip path for the slides is actually not working in Firefox (Dev Ed. 50.0, that is) and I have yet to find a way to fix that.
Follow-up: Forget what I wrote about the path not working in Firefox. It does work, but only locally – not in the online demo.
Thanks a lot for pointing that out, Nils! We’ve fixed it for the online version. Cheers, ML
Great to know that the rhomboid clip path for the slides is fixed in the new version. Great article.
I must say this website is an absolute goldmine of ideas and and useful code. Credit to the people that run it.
Wow great piece… how do i make it autoplay?
Its Perfect but how can i make it autoplay?
wow its awasome, i trying to make this slideshow autoplay, but always fails. how to make it autoplay? thankyou
best regard,
It’s awesome. Thank you.
Hi Mary Lou! your effects are great. Could you visit my website and think a cool effect for this?
I will appreciate your help.
Thank you in advanced.
The site is https://www.conjuntados.com
great gob
This is great, Thank you.
Is it feasible to make this slider automatically move?
hello Mary Lou I am ahmet from Turkey thank you your desing
if you allow me i’ll use your desing and you inspire me
how can i make it auto-play ?
I just want to make it auto play, how can i do ??? Please !!!