50Days50Projects之day01-手风琴效果
<!-- run -->
<style>
.container {
display: flex;
width: 90vw;
}
.panel{
background-size: auto 100%;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 50px;
cursor: pointer;
flex: 0.5;
margin: 10px;
position: relative;
transition: flex 0.7s ease-in;
}
.panel h3{
font-size: 24px;
position: absolute;
bottom: 20px;
left: 25%;
margin: 0px;
opacity: 0;
}
.panel.active{
flex: 5;
}
.panel.active h3 {
text-decoration: underline;
opacity: 1;
transition: opacity 0.3s ease-in 0.4s;
}
@media (max-width: 400px){
.container{
width: 100vw;
}
.panel:nth-of-type(4),.panel:nth-of-type(5){
display: none;
}
}
</style>
<div class="container">
<div class="panel active" style="background-image: url('https://cdn.yemek.com/mnresize/940/940/uploads/2015/09/humus-guncelleme-sunum-2.jpg');">
<h3>Humus</h3>
</div>
<div class="panel" style="background-image: url('https://cdn.ye-mek.net/App_UI/Img/out/650/2016/07/babagannus-resimli-yemek-tarifi(11).jpg');">
<h3>Babagannus</h3>
</div>
<div class="panel" style="background-image: url('https://img-s1.onedio.com/id-5419792dbd91753f1174225f/rev-0/w-635/f-jpg/s-06102007b3baadc508c923574e6d92857ab0e203.jpg')">
<h3>Tarator</h3>
</div>
<div class="panel" style="background-image: url('https://cdn.yemek.com/mnresize/940/940/uploads/2014/11/muhammara-one-cikan.jpg'); ">
<h3>Muhammara</h3>
</div>
<div class="panel" style="background-image: url('https://img-s2.onedio.com/id-54251fd54a693a2259536a57/rev-0/w-635/f-jpg/s-0149c4cedf6d8cb928c87a4e73d439cc2a9a4b49.jpg')">
<h3>Tarama</h3>
</div>
</div>
<script>
const panels = document.querySelectorAll(".panel");
panels.forEach(panel => {
panel.onmouseover = () => {
removeActive();
panel.classList.add("active");
}
// panel.addEventListener("click", () => {
// removeActive();
// panel.classList.add("active");
// });
})
function removeActive() {
panels.forEach(panel => {
panel.classList.remove("active");
})
}
</script>
CSS
@import url('https://fonts.googleapis.com/css2?family=Herr+Von+Muellerhoff&family=Inter:wght@700&display=swap');
*{
box-sizing: border-box;
}
body{
font-family: 'Inter', sans-serif;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
overflow: hidden;
}
.container {
display: flex;
width: 90vw;
}
.panel{
background-size: auto 100%;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 50px;
cursor: pointer;
flex: 0.5;
margin: 10px;
position: relative;
transition: flex 0.7s ease-in;
}
.panel h3{
font-size: 24px;
position: absolute;
bottom: 20px;
left: 50%;
margin: 0px;
opacity: 0;
}
.panel.active{
flex: 5;
}
.panel.active h3 {
text-decoration: underline;
opacity: 1;
transition: opacity 0.3s ease-in 0.4s;
}
@media (max-width: 600px){
.container{
width: 100vw;
}
.panel:nth-of-type(4),.panel:nth-of-type(5){
display: none;
}
}
JS
const panels = document.querySelectorAll(".panel");
panels.forEach(panel => {
panel.onmouseover = () => {
removeActive();
panel.classList.add("active");
}
// panel.addEventListener("click", () => {
// removeActive();
// panel.classList.add("active");
// });
})
function removeActive() {
panels.forEach(panel => {
panel.classList.remove("active");
})
}
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">
<link rel="stylesheet" href="style.css">
<title>Expanding Cards</title>
</head>
<body>
<div class="container">
<div class="panel active" style="background-image: url('https://cdn.yemek.com/mnresize/940/940/uploads/2015/09/humus-guncelleme-sunum-2.jpg');">
<h3>Humus</h3>
</div>
<div class="panel" style="background-image: url('https://cdn.ye-mek.net/App_UI/Img/out/650/2016/07/babagannus-resimli-yemek-tarifi(11).jpg');">
<h3>Babagannus</h3>
</div>
<div class="panel" style="background-image: url('https://img-s1.onedio.com/id-5419792dbd91753f1174225f/rev-0/w-635/f-jpg/s-06102007b3baadc508c923574e6d92857ab0e203.jpg')">
<h3>Tarator</h3>
</div>
<div class="panel" style="background-image: url('https://cdn.yemek.com/mnresize/940/940/uploads/2014/11/muhammara-one-cikan.jpg'); ">
<h3>Muhammara</h3>
</div>
<div class="panel" style="background-image: url('https://img-s2.onedio.com/id-54251fd54a693a2259536a57/rev-0/w-635/f-jpg/s-0149c4cedf6d8cb928c87a4e73d439cc2a9a4b49.jpg')">
<h3>Tarama</h3>
</div>
</div>
<script src="app.js"></script>
</body>
</html>
效果如下👇
未经作者授权,禁止转载
本文来自博客园,作者:CoderWGB,转载请注明原文链接:https://www.cnblogs.com/wgb1234/articles/16361396.html
THE END

浙公网安备 33010602011771号