<!--html--> <div id="change"> change color </div>
/*css*/
#change {
border: 1px solid black;
width: 200px;
height: 200px;
text-align: center;
line-height: 200px;
}
//js change.style.backgroundColor="purple";
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css</title>
<style>
* {
margin: 0;
padding: 0;
}
.wrap {
width: 220px;
height: 200px;
position: absolute;
top: 300px;
left: -172px;
}
.open-close {
height: 45px;
width: 48px;
background: url("open-close.png") no-repeat;
background-size: contain;
border: 1px solid grey;
border-left: none;
position: absolute;
top: 0;
right: 0;
z-index: 2;
}
.changer {
height: 150px;
width: 170px;
position: absolute;
top: 0;
left: 0;
border: 1px solid grey;
text-align: center;
padding-top: 8px;
}
.list > li {
display: block;
width: 36px;
height: 36px;
float: left;
margin-left: 9%;
margin-top: 10%;
}
#change {
border: 1px solid black;
width: 200px;
height: 200px;
text-align: center;
line-height: 200px;
}
</style>
</head>
<body>
<div class="wrap" id="wrap">
<!--html-->
<div class="open-close" id="open"></div>
<div class="changer">
<span>颜色选择器</span>
<ul class="list">
<li class="color-orange" style="background-color: orange"></li>
<li class="color-red" style="background-color: red"></li>
<li class="color-blue" style="background-color: blue"></li>
<li class="color-black" style="background-color: black"></li>
<li class="color-green" style="background-color: green"></li>
<li class="color-pink" style="background-color: pink"></li>
</ul>
</div>
</div>
<div id="change">
change color
</div>
<script>
var open = document.getElementById("open");
var wrap = document.getElementById("wrap");
var list = document.getElementById("list");
var change = document.getElementById("change");
var color_change = document.getElementsByTagName("li");
change.style.backgroundColor = "purple";
open.onmouseover = function () {
wrap.style.left = 0 + "px";
};
open.onclick = function () {
wrap.style.left = -172 + "px";
};
for (var i = 0; i < color_change.length; i++) {
color_change[i].id = i;
color_change[i].onclick = function () {
change.style.backgroundColor = color_change[this.id].style.backgroundColor;
}
}
</script>
</body>
</html>
HTMLElement.prototype.__defineGetter__("currentStyle", function () {
return this.ownerDocument.defaultView.getComputedStyle(this, null);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
.wrap {
width: 220px;
height: 200px;
position: absolute;
top: 300px;
left: -172px;
}
.open-close {
height: 45px;
width: 48px;
background: url("open-close.png") no-repeat;
background-size: contain;
border: 1px solid grey;
border-left: none;
position: absolute;
top: 0;
right: 0;
z-index: 2;
}
.changer {
height: 150px;
width: 170px;
position: absolute;
top: 0;
left: 0;
border: 1px solid grey;
text-align: center;
padding-top: 8px;
}
.list > li {
display: block;
width: 36px;
height: 36px;
float: left;
margin-left: 9%;
margin-top: 10%;
}
.color-orange {
background-color: orange;
}
.color-red {
background-color: red;
}
.color-blue {
background-color: blue;
}
.color-blank {
background-color: black;
}
.color-green {
background-color: green;
}
.color-pink {
background-color: pink;
}
#change {
border: 1px solid black;
width: 200px;
height: 200px;
text-align: center;
line-height: 200px;
}
</style>
</head>
<body>
<div class="wrap" id="wrap">
<!--html-->
<div class="open-close" id="open"></div>
<div class="changer">
<span>颜色的选择</span>
<ul class="list">
<li class="color-orange"></li>
<li class="color-red"></li>
<li class="color-blue"></li>
<li class="color-blank"></li>
<li class="color-green"></li>
<li class="color-pink"></li>
</ul>
</div>
</div>
<div id="change">
change color
</div>
<script>
HTMLElement.prototype.__defineGetter__("currentStyle", function () {
return this.ownerDocument.defaultView.getComputedStyle(this, null);
});
var open = document.getElementById("open");
var wrap = document.getElementById("wrap");
var list = document.getElementById("list");
var change = document.getElementById("change");
var color_change = document.getElementsByTagName("li");
change.style.backgroundColor="purple";
open.onmouseover = function () {
wrap.style.left = 0 + "px";
};
open.onclick = function () {
wrap.style.left = -172 + "px";
};
for (var i = 0; i < color_change.length; i++) {
color_change[i].id = i;
color_change[i].onclick = function () {
change.style.backgroundColor = color_change[this.id].currentStyle.backgroundColor;
}
}
</script>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有