在线改变div样式的颜色以及高跟宽度的JS特效代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
body { background: #00b38a center no-repeat; overflow: hidden; color: white; font-family: "Microsoft YaHei";}
a { text-decoration: none; }
#container { position:relative; width: 500px; height: 600px; background: white; margin: 0 auto;}
#container .btn { display: block; height: 90px; width: 100%; background: #2D659F; color: white; font-size: 20px; line-height: 90px; text-align: center; font-weight: bold; }
#container #box { width: 150px; height: 150px; background: #00A881; border:2px solid #272822; position: absolute; top: 50%;left:50%; margin-top: -75px; margin-left: -75px; z-index: 99999;}

#change { position: absolute; top: 90px; left: 510px; display: block; width: 150px; height:370px; background: white; }
#change div { padding:10px;}
p { color: #000;}
#change button { display:inline-block; width: 40px; height: 40px; background: #F5F6F7; border:1px solid #D8D8D8; color: #00A881;}
#change button#red { background: red;}
#change button#yellow {background: yellow;}
#change button#blue {background: blue;}

</style>
<script>
window.onload = function (){
var bt1= document.getElementById(‘red‘);
var bt2= document.getElementById(‘yellow‘);
var bt3= document.getElementById(‘blue‘);

var box = document.getElementById(‘box‘);
bt1.onclick = function (){
box.style.background = "red";
};
bt2.onclick = function (){
box.style.background = "yellow";
};
bt3.onclick = function (){
box.style.background = "blue";
};

var wd_size1 = document.getElementById(‘wd1‘);
var wd_size2 = document.getElementById(‘wd2‘);
var wd_size3 = document.getElementById(‘wd3‘);
wd_size1.onclick = function(){
box.style.width = "100px";
box.style.marginLeft="-50px";
};
wd_size2.onclick = function(){
box.style.width = "200px";
box.style.marginLeft="-100px";
};
wd_size3.onclick = function(){
box.style.width = "300px";
box.style.marginLeft="-150px";
};

var hg_size1 = document.getElementById(‘hg1‘);
var hg_size2 = document.getElementById(‘hg2‘);
var hg_size3 = document.getElementById(‘hg3‘);
hg_size1.onclick = function(){
box.style.height = "100px";
box.style.marginTop="-50px";
};
hg_size2.onclick = function(){
box.style.height = "200px";
box.style.marginTop="-100px";
};
hg_size3.onclick = function(){
box.style.height = "300px";
box.style.marginTop="-150px";
};
};
</script>
</head>
<body>
<div id="container">
<a href="" class="btn">点击设置样式</a>
<div id="box"></div>
<div id="change">
<div class="bg">
<p>选择背景</p>
<button type="button" id="red">红</button>
<button type="button" id="yellow">黄</button>
<button type="button" id="blue">蓝</button>
</div>
<div class="wd">
<p>选择宽度</p>
<button id="wd1">100</button>
<button id="wd2">200</button>
<button id="wd3">300</button>
</div>
<div class="hg">
<p>选择高度</p>
<button id="hg1">100</button>
<button id="hg2">200</button>
<button id="hg3">300</button>
</div>
</div>
</div>

</body>
</html>

时间: 2024-08-23 01:43:34

在线改变div样式的颜色以及高跟宽度的JS特效代码的相关文章

封装函数通过输入(元素,属性,目标值)改变div样式

## 假设一个div样式如下```html<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-

JS改变Div样式属性示例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

作品第一课----改变DIV样式属性

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .btn { margin: 0 auto; padding-left: 30%;} .img { width: 200px; height:

设置超链接在各种状态改变的样式颜色

设置超链接在各种状态改变的样式颜色,在html的<head>标签下面添加下面的样式,可以自己根据需要修改样式. <style> a:link {color:blue;} a:visited {color:blue;} a:hover {color:red;} a:active {color:yellow;} </style> a:link 表示未未访问的状态. a:visited 表示已访问过的状态. a:hover  表示鼠标移动到链接上时的状态. a:active 

checkbox复选框和div click事件重叠,点击div后复选框也被选中,同时改变div颜色,否则则不选中

 checkbox复选框和div click事件重叠,点击div后复选框也被选中,同时改变div颜色,否则则不选中 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> div { display: inline-block; width: 100px; margi

CSS手动改变DIV高宽

本实例代码可以使DIV可以手动改变大小 效果体验:http://hovertree.com/code/css/resize.htm 代码如下: <!DOCTYPE html> <html> <head><title>何问起</title><base target="_blank" /> <style> div { background-color:#f0f0f0; border:solid red 1p

DIV样式汇总

DIV样式汇总 最近在学习JavaScript,在做到个要控制控件样式的例子时,突然有了把常用样式汇总一下的想法,于是乎就写了以下内容,以下是以div为例来汇总的,希望对大家有些帮助. 一.常用属性: 1.Height:设置DIV的高度. 2.Width:设置DIV的宽度. 例: <div style="width:200px;height:200px;"></div> 3.margin:用于设置DIV的外延边距,也就是到父容器的距离. 例: Code 说明:m

jQuery CSS()方法改变CSS样式实例解析

转自:http://www.jbxue.com/article/24588.html 分享一个jQuery入门实例:使用CSS()方法改变现有的CSS样式表,css()方法在使用上具有多样性.其中有一种可接受两个输入参数:样式属性和样式值,两者之间用逗号分隔.比如要改变链接颜色,可以这样编写代码: $("#61dh a").css('color','#123456');//选择器‘$("#61dh a")'表示ID为‘#61dh'的元素下的所有链接.//.css(‘

jQuery中添加/改变/移除改变CSS样式例子

在jquery中对于div样式操作我们会使用到CSS() removeClass() addClass()方法来操作了,下面我们就整理了几个例子大家一起来看看吧. CSS()方法改变CSS样式 css()方法在使用上具有多样性.其中有一种可接受两个输入参数:样式属性和样式值,两者之间用逗号分隔.比如要改变链接颜色,可以这样编写代码:  代码如下 复制代码 $("#61dh a").css('color','#123456');//选择器‘$("#61dh a")’表