JSFiddle - React, Tailwind, and code Playground
HTML
<!-- Hero Slider -->
<div id="hero-section">
<i class="fas fa-angle-left" id="prevBtn"></i>
<i class="fas fa-angle-right" id="nextBtn"></i>
<div class="hero-background">
<img src="./img/Left_slide.jpg" class="left-side" alt="Ottenweller Machines">
<img src="./img/Right_slide.jpg" class="right-side" alt="Ottenweller Machines">
</div>
<div class="container">
<div class="carousel-container">
<div class="carousel-slide">
<a href="#">
<img src="./img/Machine_slide.jpg" id="lastClone" class="slide-bg" alt="The Latest Machine Capabilities">
</a>
<a href="#">
<img src="./img/History_slide.jpg" class="slide-bg" alt="The History of Ottenweller">
<div class="overlay" style="font-size: 40px; color: #fff;">
<div class="inner hundred-years">
<h2>100 years <span>in</span> 2016</h2>
<p>Learn about Our History</p>
<img src="./img/News_arrow.svg" alt="Right Arrow">
</div>
</div>
</a>
<a href="#">
<img src="./img/Join_slide.jpg" class="slide-bg" alt="Join Our Team">
<div class="overlay" style="font-size: 40px; color: #fff;">
<div class="inner join-our-team">
<h2>Join Our Team</h2>
<p>View Job Openings</p>
<img src="./img/News_arrow.svg" alt="Right Arrow">
</div>
</div>
</a>
<a href="https://www.youtube.com/watch?v=k-MzekVTzQg" target="_blank">
<img src="./img/Machine_slide.jpg" class="slide-bg" alt="The Latest Machine Capabilities">
<div class="overlay" style="font-size: 40px; color: #fff;">
<div class="inner-final">
<h2>Why partner with Ottenweller?</h2>
<img src="./img/Play_Arrow.png" alt="Play button">
<p>Watch video</p>
</div>
...
CSS
*{
padding: 0;
margin: 0;
text-decoration: none;
list-style: none;
box-sizing: border-box!important;
}
html{
overflow-x: hidden;
}
body{
font-family: 'Open Sans', sans-serif;
background-color: #161c23;
overflow: hidden;
}
.container{
position: relative;
width: 1150px;
max-width: 100%;
margin: 0 auto;
height: 100%;
}
p{
font-size: 18px;
color: #fff;
line-height: 1.8;
}
h1{
font-size: 18px;
color: #568aa8;
padding-bottom: 12px;
}
h2{
font-size: 27px;
}
h3{
font-size: 30px;
color: #fed494;
}
h4{
font-size: 22px;
}
h5{
font-size: 14px;
}
h6{
font-size: 13px;
color: #fff;
}
a{
color: #fff;
cursor: pointer;
}
i{
cursor: pointer;
}
:focus {
outline: none;
}
a:hover{
color: #74bae0;
transition: 0.3s;
}
button:hover{
cursor: pointer;
}
.col-sm-3{
vertical-align: top;
width: 25%;
display: inline-block;
}
.col-sm-6{
vertical-align: top;
width: 50%;
display: inline-block;
}
input, textarea{
background-color: transparent;
border: 1px solid #78a8bf;
margin: 5px 0;
padding: 5px;
font-size: 18px;
color: #fed494;
box-sizing : border-box;
max-width: 100%;
resize: none;
}
input::placeholder, textarea::placeholder {
color: #588eac;
}
input:active, input:focus, textarea:active, textarea:focus{
border-image-source: linear-gradient(#9cdbf8,#fdd395);
border-width: 1pt;
border-image-slice: 1;
}
.hide{
display: none!important;
}
.show{
display: inline-block!important;
}
/* Header */
header{
background: url(./img/Header_background.png) #212e39;
background-size: cover;
background-position: top;
height: 286px;
font-size: 14px;
}
header nav{
padding: 0 25px;
}
header .logo{
padding: 90px 0 0;
}
header i.fa-home{
font-size: 2em;
vertical-align: middle;
}
header a{
font-weight: 700;
transition: border-color 0.3s, color 0.3s;
}
header button{
font-family: 'Open Sans', sans-serif;
font-weight: 700;
color: #fff;
background: none;
...
JavaScript
// HERO SLIDER
const heroSlider = () => {
const carouselSlide = document.querySelector('.carousel-slide')
let carouselImages = document.querySelectorAll('.carousel-slide .slide-bg')
// Buttons
const prevBtn = document.querySelector('#prevBtn')
const nextBtn = document.querySelector('#nextBtn')
// Timer
let interval = setInterval( () => rotateSlide(), 5000)
// Counter
let counter = 1
let size = carouselImages[0].clientWidth
carouselSlide.style.transform = 'translateX(' + (-size * counter ) + 'px)'
const rotateSlide = () => {
if (counter >= carouselImages.length -1) return
carouselSlide.style.transition = "transform 0.4s ease-in-out"
counter++
carouselSlide.style.transform = 'translateX(' + (-size * counter ) + 'px)'
}
// Button Listeners
nextBtn.addEventListener('click',() => {
clearInterval(interval)
rotateSlide()
})
prevBtn.addEventListener('click', () => {
if (counter <= 0) return
carouselSlide.style.transition = "transform 0.4s ease-in-out"
counter--
carouselSlide.style.transform = 'translateX(' + (-size * counter ) + 'px)'
clearInterval(interval)
})
carouselSlide.addEventListener('transitionend', () => {
// If image is a clone, jump to original image with no animation
if (carouselImages[counter].id === 'lastClone'){
carouselSlide.style.transition = "none"
counter = carouselImages.length - 2
carouselSlide.style.transform = 'translateX(' + (-size * counter ) + 'px)'
}
if (carouselImages[counter].id === 'firstClone'){
carouselSlide.style.transition = "none"
counter = carouselImages.length - counter
carouselSlide.style.transform = 'translateX(' + (-size * counter ) + 'px)'
}
})
}
heroSlider()