手风琴案例01

js手风琴案例1

演示如图:
在这里插入图片描述
css代码:

*{
    margin: 0;
    padding: 0;
}
html,body{
    height: 100%;
    width:100%;
    background-color: black;
}
body{
    position: relative;
}
.main{

    position: absolute;
    height: 450px;
    width: 1114px;
    /*background-color: orange;*/
    left:50%;
    top:50%;
    transform: translate(-50%,-50%);

}
.main ul{
    list-style: none;
}
.main ul li{
    float: left;
    width: 100px;
    height: 400px;
    transition: all 1s;
    border: 1px solid #000000;
}
.main ul li .li-active{
    width: 500px;
    height: 450px;
}
.main ul li:nth-child(1){
    background: url("../images/ruili_img1.jpg")no-repeat center/cover;
}
.main ul li:nth-child(2){
    background: url("../images/ruili_img2.jpg")no-repeat center/cover;
    opacity: 0.8;
}
.main ul li:nth-child(3){
    background: url("../images/ruili_img3.jpg")no-repeat center/cover;
    opacity: 0.8;
}
.main ul li:nth-child(4){
    background: url("../images/ruili_img4.jpg")no-repeat center/cover;
    opacity: 0.7;
}
.main ul li:nth-child(5){
    background: url("../images/ruili_img5.jpg")no-repeat center/cover;
    opacity: 0.7;
}
.main ul li:nth-child(6){
    background: url("../images/ruili_img6.jpg")no-repeat center/cover;
    opacity: 0.6;
}
.main ul li:nth-child(7){
    background: url("../images/ruili_img7.jpg")no-repeat center/cover;
    opacity: 0.5;
}
.main ul li div{
    width: 100px;
    height: 400px;
}
.main ul li p{
    width: 80px;
    height: 50px;
    line-height: 50px;
    color: #ffffff;
    padding-left: 20px;
    background-color: #666666;
    opacity: 0.8;
    transition: all 1s;
}
.main ul li .p-active{
    width: 480px;
    height: 50px;
    /*transition: all 1s;*/
}
.main ul li.li-active{
    width: 500px;
    height: 400px;

}

HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>手风琴练习</title>
    <link rel="stylesheet" href="css/手风琴练习.css">
    <script src="js/手风琴练习.js"></script>
</head>
<body>
    <div class="main">
        <ul>
            <li class="li-active">
                <div></div>
                <p class="p-active">服饰</p>
            </li>
            <li>
                <div></div>
                <p>服饰</p>
            </li>
            <li>
                <div></div>
                <p>服饰</p>
            </li>
            <li>
                <div></div>
                <p>服饰</p>
            </li>
            <li>
                <div></div>
                <p>服饰</p>
            </li>
            <li>
                <div></div>
                <p>服饰</p>
            </li>
            <li>
                <div></div>
                <p>服饰</p>
            </li>

        </ul>
    </div>
</body>
</html>

js代码:

window.onload = function () {
    let lis = document.querySelectorAll(".main li");
    let ps = document.querySelectorAll("p");
        lis.forEach((item,index)=>{
           item.onmouseover = function () {
               lis.forEach((el,i)=>{
                   el.className = "";
                   ps[i].classList.remove("p-active");
               });
               this.className = "li-active";
               ps[index].classList.add("p-active");
           }
        });
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值