Jquery换肤

下面是通过jquery,点击更换背景按钮来触发事件,从而改变body背景图片,先看下面的源码啊:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>背景图片</title>
    <script src="http://cdn.bootcss.com/jquery/3.0.0-beta1/jquery.js"></script>
    <style type="text/css">

    *{margin: 0; margin: 0; border: 0;}
    html{width: 100%; height: 100%;}
    body{width: 100%; height: 100%; background-image: url(1.jpg); 

    overflow: hidden;
    font-family: "微软雅黑","'Segoe UI', Tahoma, Geneva, Verdana, sans-serif";
    }

    .content{color: white; background-color: #000; opacity: 0.3;}
    .content h1{font-size: 60px; text-align: center;}
    .content p{text-align: right;}
    .content p input{height: 30px; background-color: orange;  }
    .footer{position: relative;
    width: 1200px;
    height:auto;
    margin: 0 auto;
    margin-top: 50px;
    }
    .f-content{
      color: white;
      width: 1200px;
      margin: 0 auto;
      height:auto;
      font-size: 30px;
     bottom: 0;

    }
    </style>
    <script>
           $(document).ready(function(){

             var imgcount=4;//背景图片数量
             var imgNow=0;//显示的背景图片位置
             $("#bgbtn").click(function(){
                imgNow=(imgNow+1)%imgcount;//数值在0-3之间循环
                bgshow(imgNow) ;
             })

           })
           function bgshow(imgNow){
               var imgArry =new Array("url(1.jpg)","url(2.jpg)","url(3.jpg)","url(4.jpg)");//所需的图片url地址
                 var b=$("body");      
                 var imgsr=imgArry[imgNow];
                 b.css("background-image",imgsr);
           }

    </script>
</head>
<body>
 <div class="content">
   <h1>周杰伦-晴天</h1>
   <p><input type="button" id="bgbtn" value="点击更换背景" onclick="test()"/><p>
 </div>
 <div class="footer">
   <div class="f-content">
     <h3>晴天</h3>
     <p>从出生那年就飘着</p>
     <p>童年的荡秋千</p>
     <p>随记忆一直晃到现在</p>
     <p>rui sou sou xi dou xi la</p>
     <p>吹着前奏望着天空...<input type="button" value="更多" onclick="bgshow(2)" style="background-color:white; opacity:0.2;"/></p>

   </div>
 </div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值