js Dom实现换肤效果
本文实例为大家分享了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
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持安科网。
相关推荐
luvhl 2020-08-17
liaoxuewu 2020-06-26
北京老苏 2020-06-25
Lophole 2020-06-14
SIMONDOMAIN 2020-06-14
firstboy0 2020-06-14
88274956 2020-11-03
runner 2020-09-01
梦的天空 2020-08-25
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
sunzhihaofuture 2020-06-21
FEvivi 2020-06-16
坚持着执着 2020-06-16
waterv 2020-06-14
xiaoge00 2020-06-14
firejq 2020-06-14
e度空间 2020-06-12
zhongweinan 2020-06-10