频道栏目
首页 > 资讯 > JavaScript > 正文

Jquery换肤

16-05-11        来源:[db:作者]  
收藏   我要投稿

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

<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>
<h1><code class="hljs xml">周杰伦-晴天</code></h1>
<p><code class="hljs xml"><input id="bgbtn" onclick="test()" type="button" value="点击更换背景" /></code></p>
<p>&nbsp;</p>
<h3><code class="hljs xml">晴天</code></h3>
<p><code class="hljs xml">从出生那年就飘着</code></p>
<p><code class="hljs xml">童年的荡秋千</code></p>
<p><code class="hljs xml">随记忆一直晃到现在</code></p>
<p><code class="hljs xml">rui sou sou xi dou xi la</code></p>
<p><code class="hljs xml">吹着前奏望着天空...<input onclick="bgshow(2)" type="button" value="更多" /></code></p>
相关TAG标签
上一篇:hadoop集群2.7.2搭建
下一篇:前端框架
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站