js Dom实现换肤效果

不是所有的故事都能成为你的眼睛里的色彩,因为岁月会淡化你的颜色。当你的人生路走得不平顺的时候,不要忘记了,你只是走过这条路而已,走过以后一切只能任时光处置。

本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>换肤</title>
 <link rel="stylesheet" rel="nofollow noopener noreferrer" href="base.css">
 <link rel="stylesheet" rel="nofollow noopener noreferrer" href="spring.css">
 <script src="change.js"></script> 
</head>
<body>
 <header>
  <span>季节</span>
  <button>换肤</button>
 </header>
 <div class="main">
 </div>
</body>
</html>

基本样式文件

header{
 position: absolute;
 top:0px;
 width:1366px;
 height: 60px;
 text-align: center;
}
header>span{
 line-height: 60px;
}
header>button{
 width:60px;
 height:45px;
 position: absolute;
 right:30px;
 margin-top:8px;
}
.main{
 margin-top: 60px;
 width:1366px;
 height:600px;
} 

spring.css文件

html,body{
 padding: 0px;
 margin: 0px;
}
header{
 background-color: #C0FF3E;
}
.main{
 background: url(img/spring.jpg) no-repeat;
 background-size: 1366px 600px;
}

summer.css文件

html,body{
 padding: 0px;
 margin: 0px;
}
header{
 background-color: #76EE00;
}
.main{
 background: url(img/summer.jpg) no-repeat;
 background-size: 1366px 600px;
}

change,js文件

function change(){
 var link=document.getElementsByTagName("link")[1];
 var btn=document.getElementsByTagName("button")[0];
 btn.onclick=function(){
  if(link.rel="nofollow noopener noreferrer" href=="http://localhost:8000/BOM%E5%AD%A6%E4%B9%A0/spring.css"){
   link.rel="nofollow noopener noreferrer" href="summer.css";
  }else{
   link.rel="nofollow noopener noreferrer" href="spring.css";
  }
 };
}
window.onload=function(){
 change();
};

主要是取得link标签对象,替换link里面的属性href

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

您可能有感兴趣的文章
JS实现换肤功能的方法实例详解

微信小程序实现换肤功能

webpack构建换肤功能的思路详解

jQuery基于cookie实现换肤功能实例

jQuery结合jQuery.cookie.js插件实现换肤功能示例