The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Below is the html code for this video.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Accordion</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="accordion">
<ul>
<li tabindex="1" id="first-img">
<div>
<a href="#">
<h2>Image 1</h2>
<p>Facilis repellat omnis voluptatibus repudiandae explicabo! Vel placeat voluptate quos</p>
</a>
</div>
</li>
<li tabindex="2" id="second-img">
<div>
<a href="#">
<h2>Image 2</h2>
<p>Atque perferendis molestias est unde reiciendis, odio accusamus at magnam odit laborum</p>
</a>
</div>
</li>
<li tabindex="3" id="third-img">
<div>
<a href="#">
<h2>Image 3</h2>
<p>Inventore neque harum tempore minima ex exercitationem aperiam, distinctio unde</p>
</a>
</div>
</li>
<li tabindex="4" id="forth-img">
<div>
<a href="#">
<h2>Image 4</h2>
<p>Ab hic, odio illo nesciunt assumenda ex, similique magni, quia cumque omnis odit quae</p>
</a>
</div>
</li>
<li tabindex="5" id="fifth-img">
<div>
<a href="#">
<h2>Image 5</h2>
<p>Provident officia aspernatur minus atque? Error ex suscipit odit repellendus eos est</p>
</a>
</div>
</li>
</ul>
</div>
<script src="index.js"></script>
</body>
</html>
Below is the css code for this video.
style.css
* {
margin: 0;
padding: 0;
transition: all 0.5s ease;
}
body {
height: 100vh;
width: 100%;
background-color: #b2ac88;
font-family: 'Times New Roman', Times, serif;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
backdrop-filter: blur(8.2px) grayscale(82%);
}
.accordion {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 55vh;
width: 82%;
overflow: hidden;
}
.accordion ul {
display: flex;
width: 100%;
list-style: none;
}
.accordion ul li {
position: relative;
height: 55vh;
width: 20%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
vertical-align: middle;
}
.accordion ul li div {
display: block;
width: 100%;
overflow: hidden;
}
.accordion ul li div a {
position: relative;
display: block;
height: 55vh;
width: 100%;
color: #ffffff;
text-decoration: none;
padding: 15px 30px;
vertical-align: bottom;
z-index: 3;
box-sizing: border-box;
}
.accordion ul li div a * {
position: relative;
width: 100%;
transform: translateX(-20px);
text-overflow: ellipsis;
white-space: nowrap;
z-index: 5;
overflow: hidden;
opacity: 0;
}
.accordion ul li div a h2 {
top: 45vh;
font-size: 16px;
text-transform: uppercase;
text-overflow: clip;
margin-bottom: 0.5%;
}
.accordion ul li div a p {
top: 46vh;
font-size: 12px;
}
.accordion ul:hover li, .accordion ul:focus-within li {
width: 10%;
}
.accordion ul li:focus {
outline: none;
}
.accordion ul:hover li:hover, .accordion ul li:focus, .accordion ul:focus-within li:focus {
width: 60%;
}
.accordion ul:hover li:hover a, .accordion ul li:focus a, .accordion ul:focus-within li:focus a {
background: linear-gradient(transparent 46vh, #00000080 46vh);
}
.accordion ul:hover li:hover a *, .accordion ul li:focus a *, .accordion ul:focus-within li:focus a * {
opacity: 1 !important;
transform: translateX(0);
}
.accordion ul:hover li a * {
opacity: 0 !important;
}
Below is the javascript code for this video.
index.js
var firstImg = document.getElementById("first-img");
firstImg.style.backgroundImage = "url(https://images.unsplash.com/photo-1662522229766-fb5abaa9de6d?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1374&q=80)";
firstImg.addEventListener("mouseover", function () { document.body.style.backgroundImage = firstImg.style.backgroundImage; });
firstImg.addEventListener("mouseout", function () {
document.body.style.backgroundImage = "";
document.body.style.backgroundColor = "#b2ac88";
});
var secondImg = document.getElementById("second-img");
secondImg.style.backgroundImage = "url(https://images.unsplash.com/photo-1649207689167-7f712ba31dd9?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80)";
secondImg.addEventListener("mouseover", function () { document.body.style.backgroundImage = secondImg.style.backgroundImage; });
secondImg.addEventListener("mouseout", function () {
document.body.style.backgroundImage = "";
document.body.style.backgroundColor = "#b2ac88";
});
var thirdImg = document.getElementById("third-img");
thirdImg.style.backgroundImage = "url(https://images.unsplash.com/photo-1675371788315-60fa0ef48267?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1632&q=80)";
thirdImg.addEventListener("mouseover", function () { document.body.style.backgroundImage = thirdImg.style.backgroundImage; });
thirdImg.addEventListener("mouseout", function () {
document.body.style.backgroundImage = "";
document.body.style.backgroundColor = "#b2ac88";
});
var forthImg = document.getElementById("forth-img");
forthImg.style.backgroundImage = "url(https://images.unsplash.com/photo-1650844702349-d969b81326c7?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80)";
forthImg.addEventListener("mouseover", function () { document.body.style.backgroundImage = forthImg.style.backgroundImage; });
forthImg.addEventListener("mouseout", function () {
document.body.style.backgroundImage = "";
document.body.style.backgroundColor = "#b2ac88";
});
var fifthImg = document.getElementById("fifth-img");
fifthImg.style.backgroundImage = "url(https://images.unsplash.com/photo-1683016707500-0ab27d0ebf30?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80)";
fifthImg.addEventListener("mouseover", function () { document.body.style.backgroundImage = fifthImg.style.backgroundImage; });
fifthImg.addEventListener("mouseout", function () {
document.body.style.backgroundImage = "";
document.body.style.backgroundColor = "#b2ac88";
});
Thanks for visiting