手风琴效果

<body>
<div class="bg bg-box-1"></div>
<div class="bg bg-box-2"></div>
<div class="bg bg-box-3"></div>
<div class="bg bg-box-4"></div>
<div id="bg_wrap">
    <div id="content">
        <ul>
            <li class="curr">
               <div class="left">
                   <p>尼尔机械纪元1</p>
               </div>
            </li>
            <li>
                <div class="left">
                    <p>尼尔机械纪元2</p>
                </div>
            </li>
            <li>
                <div class="left">
                    <p>尼尔机械纪元3</p>
                </div>
            </li>
            <li>
                <div class="left">
                    <p>尼尔机械纪元4</p>
                </div>
            </li>
        </ul>
    </div>
</div>

</body>

css:





*{
    padding:0;
    margin:0;
    list-style:none;
}
body{
    width:100%;
    height:100%;
}
#bg_wrap{
    width:100%;
    height:100%;
    position:absolute;
    top:0;
    left:0;
}
.bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
.bg-box-1{
    background: url('../img/1.jpg') no-repeat center/cover;
}
.bg-box-2{
    background: url('../img/2.jpg') no-repeat center/cover;
}
.bg-box-3{
    background: url('../img/3.jpg') no-repeat center/cover;
}
.bg-box-4{
    background: url('../img/4.jpg') no-repeat center/cover;
}
#content{
    position: absolute;
    overflow: hidden;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    width: 1000px;
    height: 400px;
}
ul{
    width:120%;
}
li{
    width:100px;
    float:left;
    height: 400px;
    transition:all 1s;
}
li:nth-child(1){
    background:url(../img/1.jpg) no-repeat center/cover;
}
li:nth-child(2){
    background:url(../img/2.jpg) no-repeat center/cover;
}
li:nth-child(3){
    background:url(../img/3.jpg) no-repeat center/cover;
}
li:nth-child(4){
    background:url(../img/4.jpg) no-repeat center/cover;
    width:700px;
}
#content .left{
    width:100px;
    height:100%;
    background:rgba(0,0,0,0.5);
}
#content .left p{
   padding:20px 40px;
    color:#fff;
}


js:

/**
 * Created by SlzStar on 2017/9/26.
 */
window.onload = function () {
    $("li").mouseover(function(){
        var that  = $(this);
        if(!$(this).hasClass("curr")){
            $("li").removeClass("curr");
            $(this).addClass("curr");
            //改变背景色;
            $("li").each(function(index){
                console.log(index)  //得到1-3所有的;所以拍判断有curr的时候才用他的index;
                if($(this).hasClass("curr")){
                    $(".bg").fadeOut(300);
                    $(".bg:eq("+index+")").fadeIn(500);
                }


            })


            //手风琴效果
            $('.curr').stop().animate({
                width: 700
            }, 100, 'linear');


            $("li").not(".curr").stop().animate({
                width:100
            },100,"linear")
        }


    })
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值