Slider Horizontal Hover
by webgleb
HTML
<div class="container">
<div class="slide active" style="background-image: url('https://images.unsplash.com/photo-1516550893923-42d28e5677af?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1650&q=80')">
<h3>Vienna</h3>
</div>
<div class="slide" style="background-image: url('https://images.unsplash.com/photo-1565426873118-a17ed65d74b9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1650&q=80')">
<h3>Budapest</h3>
</div>
<div class="slide" style="background-image: url('https://images.unsplash.com/photo-1610016302534-6f67f1c968d8?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1650&q=80')">
<h3>Milan</h3>
</div>
<div class="slide" style="background-image: url('https://images.unsplash.com/photo-1539037116277-4db20889f2d4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1650&q=80')">
<h3>Barcelona</h3>
</div>
<div class="slide" style="background-image: url('https://images.unsplash.com/photo-1540224485413-4c7939106f3a?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1650&q=80')">
<h3>Berlin</h3>
</div>
</div>
CSS
@import url("https://fonts.googleapis.com/css?family?Muli&display=swap");
* {
box-sizing: border-box;
}
body {
font-family: 'Muli', sans-serif;
overflow: hidden;
margin: 0;
background: rgb(2,0,36);
background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(90,107,117,1) 100%);
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.container {
width: 100%;
display: flex;
padding: 0 20px;
}
.slide {
height: 80vh;
border-radius: 20px;
margin: 10px;
cursor: pointer;
color: white;
flex: 1;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
position: relative;
transition: all 500ms ease-in-out;
}
.slide h3 {
position: absolute;
font-size: 24px;
bottom: 20px;
left: 20px;
margin: 0;
opacity: 0;
}
.slide.active {
flex: 10;
}
.slide.active h3 {
opacity: 1;
transition: opacity 0.3s ease-in 0.4s;
}
JavaScript
const slides = document.querySelectorAll('.slide');
slides.forEach((slide) => {
slide.addEventListener('mouseover', () => {
clearActiveClasses();
slide.classList.add('active');
})
})
function clearActiveClasses() {
slides.forEach((slide) => {
slide.classList.remove('active');
})
}