时间:2020-11-10 15:46:27 | 栏目:JavaScript代码 | 点击:次
本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>换肤</title> <link rel="stylesheet" href="base.css"> <link rel="stylesheet" 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.href=="http://localhost:8000/BOM%E5%AD%A6%E4%B9%A0/spring.css"){ link.href="summer.css"; }else{ link.href="spring.css"; } }; } window.onload=function(){ change(); };
主要是取得link标签对象,替换link里面的属性href