dom----网页换皮肤

//html部分
<style>
    *{margin: 0;padding: 0;}
    html,body{
      width:100%;
      height:100%;
    }
    #box{
        width: 100%;
        height: 0;
        background:#abcdef;
        overflow:hidden;
        transition:height 2s ease;
    }
    ul{
      list-style:none;
      padding:0;
      margin:0;
      height:100%;
      display:flex;
      justify-content:space-evenly;
      align-items: center;
    }
    li{
      width:320px;
      height:200px;
    }
    li:nth-child(1){
      background:url(./images/1.jpg) 100%/320px;
    }
    li:nth-child(2){
      background:url(./images/2.jpg)  100%/320px;
    }
    li:nth-child(3){
      background:url(./images/3.jpg)  100%/320px;
    }
    </style>
<script>
    var btn = document.querySelector('button')      //获取按钮
    var box = document.querySelector('#box')        //获取盒子
    btn.onclick = function(){                        //给按钮绑定点击事件
        if(this.innerText == '打开'){
            this.innerText = '关闭'
            box.style.height = '200px'
        }else{
            this.innerText = '打开'
            box.style.height = '0'
            }
    }

    var lis = document.querySelectorAll('li')          //获取li元素
    for(var i = 0;i<lis.length;i++){                    //通过循环得到li的索引
        lis[i].onclick = function(){                    //给每一个li绑定点击事件
                 //此处的需要用到取行内式以外样式的获取方式
            var img = window.getComputedStyle.backgroundImage    
            document.body.backgroundImage = img +' 100% 100%/100% 100%'    //试图片平铺
            btn.innerText = '打开'
            btn.style.height = '0'
        }
    }
</script>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值