Using Text Animations with Slick Slider
Adding text animations to your slider can help emphasize content and create smooth transitions between slides.
by Nick Hulea
HTML
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>
<header class="hero-text">
<div class="hero" data-arrows="true" data-autoplay="true">
<!--.hero-slide-->
<div class="hero-slide">
<img alt="Mars Image" class="img-responsive cover" src="https://raw.githubusercontent.com/solodev/text-animations-slick-slider/master/images/rocket.jpg">
<div class="header-content text-white position-absolute slide-content col-lg-4">
<h1 class="mb-4">Be part of the <span class="d-block font-weight-bold">Lunar XPerience</span></h1>
<a class="btn btn-primary btn-lg w-max mt-2" href="#" tabindex="0">Tour Our Ships</a>
</div>
</div>
<!--.hero-slide-->
<div class="hero-slide">
<img alt="Mars Image" class="img-responsive cover" src="https://raw.githubusercontent.com/solodev/text-animations-slick-slider/master/images/mars-mission.jpg">
<div class="header-content text-white position-absolute slide-content col-lg-4">
<h1 class="mb-4">LunarXP Voted Best Mars Mission</h1>
<p class="font-weight-bold">Inc. magazine today ranked LunarXP as the fastest growing company in the Mars Mission category.</p>
<a class="btn btn-primary btn-lg w-max mt-2" href="#" tabindex="0">Read More</a>
</div>
</div>
<!--.hero-slide-->
<div class="hero-slide">
<img alt="Mars Image" class="img-responsive cover" src="https://raw.githubusercontent.com/solodev/text-animations-slick-slider/master/images/cosmos.jpg">
<div class="header-content text-white position-absolute slide-content col-lg-4">
<p>Our fleet of advanced spacecraft have revolutionized the lunar economy and provided safe...
CSS
header {
overflow: hidden;
}
.hero-text h2 {
margin-bottom: 50px;
}
.hero-text .hero {
position: relative;
}
.hero-text .hero .hero-slide a:hover span {
color: #033a71;
}
.hero .hero-slide img {
width: 100%;
height: 600px;
object-fit: cover;
object-position: top center;
}
.hero .hero-slide .header-content {
top: 20%;
margin-left: 8rem;
max-width: 550px;
width: 100%;
padding: 2rem;
}
.slide-content {
padding: 10px 20px 10px 0;
}
.slide-content .h1 {
font-size: 62px;
}
.btn-primary {
background-color: #5302FE;
border: #111;
border-radius: 0;
}
/** Text Animation **/
@-webkit-keyframes fadeInUpSD {
0% {
opacity: 0;
-webkit-transform: translateY(100px);
transform: translateY(100px);
}
100% {
opacity: 1;
-webkit-transform: none;
transform: none;
}
}
@keyframes fadeInUpSD {
0% {
opacity: 0;
-webkit-transform: translateY(100px);
transform: translateY(100px);
}
100% {
opacity: 1;
-webkit-transform: none;
transform: none;
}
}
.fadeInUpSD {
-webkit-animation-name: fadeInUpSD;
animation-name: fadeInUpSD;
}
.slick-active .slide-content {
animation-name: fadeInUpSD;
animation-duration: 1s;
opacity: 1;
width: 100%;
padding: 10px 20px 30px 0;
}
/* Text Animation End **/
.slick-dots {
position: absolute;
bottom: 10px;
display: block;
width: 100%;
padding: 0;
list-style: none;
text-align: center;
}
.slick-dots li {
position: relative;
display: inline-block;
width: 20px;
height: 20px;
margin: 0 5px;
padding: 0;
cursor: pointer;
}
.slick-active button {
background: #d60e96;
}
.slick-dots li button {
font-size: 0;
line-height: 0;
display: block;
width: 20px;
height: 20px;
padding: 5px;
cursor: pointer;
border-radius: 50%;
border: 0;
outline: none;
}
.slick-dots li button::before {
font-size: 18px;
color: #fff;
opacity: 1;
}
/* Media Queries */
@media (max-width: 768px) {
.hero-text .hero...
JavaScript
jQuery(document).ready(function ($) {
$('.hero').slick({
dots: true,
infinite: true,
speed: 500,
fade: !0,
cssEase: 'linear',
slidesToShow: 1,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 8000,
draggable: false,
arrows: false,
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
infinite: true
}
},
{
breakpoint: 768,
settings: {
draggable: true,
}
},
{
breakpoint: 600,
settings: {
slidesToShow: 1,
draggable: true,
slidesToScroll: 1
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
draggable: true,
slidesToScroll: 1
}
}
]
});
});