Last active
April 25, 2018 17:17
-
-
Save cbejensen/360d9e9817fc8a2dab345f804cd7b990 to your computer and use it in GitHub Desktop.
Easy Carousel with Text
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
<div class="easy-slides"> | |
<div class="easy-slide active" style="background-image:url('https://source.unsplash.com/random/800x400');"></div> | |
<div class="easy-slide" style="background-image:url('https://source.unsplash.com/random/700x400');"></div> | |
<div class="easy-slide" style="background-image:url('https://source.unsplash.com/random/800x300');"></div> | |
<div class="easy-slide-text"> | |
Hello World! | |
</div> | |
</div> |
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
const slides = document.querySelectorAll('.easy-slide'); | |
let activeSlide = -1; | |
setInterval(function() { | |
activeSlide++; | |
updateSlide(); | |
}, 5000); | |
function updateSlide() { | |
slides.forEach((slide, i) => { | |
if (activeSlide % 3 === i) { | |
slide.classList.add('active'); | |
} else { | |
slide.classList.remove('active'); | |
} | |
}) | |
} |
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
.easy-slides, .easy-slide { | |
height: 90vh; | |
} | |
.easy-slides { | |
position: relative; | |
background: #000; | |
} | |
.easy-slide { | |
width: 100%; | |
position: absolute; | |
top: 0; | |
left: 0; | |
background-size: cover; | |
background-position: center; | |
opacity: 0; | |
transition: opacity 1s; | |
-webkit-transition: opacity 1s; | |
-moz-transition: opacity 1s; | |
-ms-transition: opacity 1s; | |
-o-transition: opacity 1s; | |
} | |
.easy-slide.active { | |
opacity: 0.6; | |
} | |
.easy-slide-text { | |
position: absolute; | |
width: 100%; | |
padding: 0 10%; | |
left: 50%; | |
top: 50%; | |
transform: translate(-50%,-50%); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment