// Get the container element
var btnContainer = document.getElementById("item");
// Get all buttons with class="btn" inside the container
var btns = btnContainer.getElementsByClassName("items");
// Loop through the buttons and add the active class to the current/clicked button
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function() {
//this.classList.add("active");
var current = document.getElementsByClassName("active");
// If there's no active class
if (current.length > 0) {
current[0].className = current[0].className.replace(" active", "");
}
this.className += " active";
});
}
.accordion {
width: 100%;
max-width: 1080px;
height: 250px;
overflow: hidden;
margin: 50px auto;
}
.accordion ul {
width: 100%;
display: table;
table-layout: fixed;
margin: 0;
padding: 0;
}
.accordion ul li {
display: table-cell;
vertical-align: bottom;
position: relative;
width: 16.666%;
height: 250px;
background-repeat: no-repeat;
background-position: center center;
transition: all 500ms ease;
}
.accordion ul li div {
display: block;
overflow: hidden;
width: 100%;
}
.accordion ul li div a {
display: block;
height: 250px;
width: 100%;
position: relative;
z-index: 3;
vertical-align: bottom;
/*padding: 15px 20px;*/
box-sizing: border-box;
color: #fff;
text-decoration: none;
font-family: Open Sans, sans-serif;
transition: all 200ms ease;
}
.accordion ul li div a *:not(.bar){
opacity: 0;
margin: 0;
width: 100%;
text-overflow: ellipsis;
position: relative;
z-index: 5;
white-space: nowrap;
overflow: hidden;
-webkit-transform: translateX(-20px);
transform: translateX(-20px);
-webkit-transition: all 400ms ease;
transition: all 400ms ease;
}
.accordion ul li div a .bar{
writing-mode: tb-rl;
transform: rotate(-180deg);
position: absolute;
background-color: yellowgreen;
padding: 10px;
height: 100%;
width: auto;
right: 0;
top: 0;
display: block;
box-sizing: border-box;
}
.accordion ul li div a h2 {
font-family: Montserrat, sans-serif;
text-overflow: clip;
font-size: 24px;
text-transform: uppercase;
margin-bottom: 2px;
top: 160px;
}
.accordion ul li div a p {
top: 160px;
font-size: 13.5px;
}
.accordion ul li:nth-child(1) { background-image: url("https://picsum.photos/id/237/200/300"); background-size: 100%;background-size: cover; }
.accordion ul li:nth-child(2) { background-image: url("https://picsum.photos/id/236/200/300"); background-size: cover;}
.accordion ul li:nth-child(3) { background-image: url("https://picsum.photos/id/235/200/300"); background-size: cover;}
.accordion ul li.active { width: 60%; }
.accordion ul li a { background: rgba(0, 0, 0, 0.5); }
.accordion ul li.active a, .accordion ul li:hover a { background: rgba(0, 0, 0, .0); }
.accordion ul li.active a * {
opacity: 1;
-webkit-transform: translateX(0);
transform: translateX(0);
}
1条答案
按热度按时间dy2hfwbg1#
结果如你所愿吗?你能检查一下吗?