Adding a Hero Slider to your Website Using FlexSlider

An effective hero slider provides users with the most valuable content on your site aligned with your goals and prompts them to take action. In Part I of our FlexSlider Series, we provide you with the code you need to easily add a hero slider to your homepage using the fully responsive jQuery toolkit FlexSlider by woothemes.

Below is the HTML, CSS, and JavaScript to add this functionality to your website.

Step 1

Add the HTML below to where you’d like to place your hero slider

<!-- @zone - hightlighted -->
<!--Showshow-->
<div class="container slider-container">
<div class="row">
<div class="col-md-12 slider-left">
<section class="flexslider-wrapper">
<div id="main-slider" class="flexslider" data-transition="fade" data-page-class="slider-full-width">
<div class="slides">
<div data-slide-alt="alt" data-slide-bg-stretch=true class="slide slide-bg" data-slide-bg="https://www.solodev.com/assets/flexslider/slide1.jpg">
<div class="slide-caption">
<div class="row">
<div class="col-md-12">
<div class="slide-text">
<div class="slide-title">This is Slide #1</div>
This is text for the first slide.
</div>
</div>
</div>
</div>
</div>
<div data-slide-alt="alt" data-slide-bg-stretch=true class="slide slide-bg" data-slide-bg="https://www.solodev.com/assets/flexslider/slide2.jpg">
<div class="slide-caption">
<div class="row">
<div class="col-md-12">
<div class="slide-text">
<div class="slide-title">This is Slide #2</div>
This is text for the second slide.
</div>
</div>
</div>
</div>
</div>
<div data-slide-alt="alt" data-slide-bg-stretch=true class="slide slide-bg" data-slide-bg="https://www.solodev.com/assets/flexslider/slide3.jpg">
<div class="slide-caption">
<div class="row">
<div class="col-md-12">
<div class="slide-text">
<div class="slide-title">This is Slide #3</div>
This is text for the third slide.
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</div>
</div>

Step 2

Add the CSS below to the main stylesheet of your website

.slider_background{
background:#eee;
}
.slide-caption {
padding:0;
height:76px;
margin:0;
margin-top:34%;
width:auto;
}
.slide-caption .btn-primary{
width:100%;
height:100%;
display:inline-block;
vertical-align: middle;
font-weight:normal;
font-size:18px;
}
.slide-caption .btn-primary span{
display:inline-block;
vertical-align: middle;
}
.centerer{
height:100%;
width:0;
display:inline-block;
vertical-align: middle;
}
.slide-caption{
color:#fff;
background-color:#09455c;
}
.slider-container{
overflow:hidden;
}
.slide-caption .row, .slide-caption .col-md-2{
height:100%;
}
.slide-caption .slide-text{
padding:6px 45px;
}
.slider-container .slider-left, .slider-container .slider-right {
padding:0;
margin-bottom: -9999px;
padding-bottom: 9986px;
}
.slider-right{
padding:15px;
background:#09455c;
}
.slider-right h2{
font-weight:normal!important;
font-family: "Museo-300", Helvetica Neue, Helvetica, Arial, sans-serif;
color:#fff !important;
text-transform: uppercase;
font-size:18px;
line-height: 26px;
margin: 15px;
padding-left: 15px;
}
.slider-right ul{
margin:0;
padding:0;
list-style:none;
}
.slider-right .arrow{
-webkit-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
line-height:normal;
float:right;
color:#346100;
font-weight: 100;
font-size:14px;
}
.slide-title{
margin-bottom: 3px;
font-size:20px;
color:#fff;
}
.slider-right ul li a{
-webkit-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
display:block;
padding:20px 30px;
background:#f6f5f6;
text-transform: uppercase;
font-size:16px;
color:#475055;
margin-bottom: -1px;
}
.slider-right ul li a:hover{
background:#1489b5;
text-decoration:none;
color:#fff;
}
.slider-right ul li a:hover .arrow{
color:#fff;
}
.slider-right .glyphicon{
display:inline-block;
}

Step 3

Add the JavaScript below to a file called slider.js

$(document).ready(function () {
if (jQuery().flexslider) {
//flexslider ticker
$('.flexslider-ticker').each(function() {
var tickerSettings = {
animation: "slide",
animationLoop: false,
selector: ".items > .item",
move: 1,
controlNav: false,
slideshow: true,
direction: 'vertical'
};
$(this).flexslider(tickerSettings);
});
// flexsliders
$('.flexslider').each(function() {
var sliderSettings = {
animation: $(this).attr('data-transition'),
selector: ".slides > .slide",
controlNav: false,
smoothHeight: true,
prevText: "",
nextText: "",
sync: $(this).data('slidernav') || '',
start: function(slider) {
if (slider.find('[data-slide-bg-stretch=true]').length > 0) {
slider.find('[data-slide-bg-stretch=true]').each(function() {
if ($(this).data('slide-bg')) {
$(this).backstretch($(this).data('slide-bg'));
// $(this).data('slide-bg');
}
});
}
}
};

$('html').addClass('has-flexslider');
$(this).flexslider(sliderSettings);
});
$(window).delay(1000).trigger('resize'); //make sure height is right load assets loaded
}})

Step 4

Add the includes below to the page where your slider lives

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-backstretch/2.0.4/jquery.backstretch.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flexslider/2.6.2/flexslider.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/flexslider/2.6.2/jquery.flexslider.js"></script>

Demo on JSFiddle

Download from GitHub

Originally Posted here on the Solodev Web Design Blog

Get daily web design tutorials in your inbox by subscribing to the Solodev Blog at solodev.com/blog/!
Brought to you by the Solodev Team. Solodev is a cloud-based web content management system that empowers users with the freedom to bring amazing web designs to life.