<Html>
<Head>
<Style type = "text/css">
# D1 {
Position: absolute;
Width: 300px;
Height: 300px;
Visibility: hidden;
Color: # fff;
Background: #555;
}
# D2 {
Position: absolute;
Width: 300px;
Height: 300px;
Visibility: hidden;
Color: # fff;
Background: #777;
}
# D3 {
Position: absolute;
Width: 150px;
Height: 150px;
Visibility: hidden;
Color: # fff;
Background: #999;
}
</Style>
<Script>
Var d1, d2, d3, w, h;
Window. onload = function (){
D1 = document. getElementById ('d1 ');
D2 = document. getElementById ('d2 ');
D3 = document. getElementById ('d3 ');
Back ();
W = window. innerWidth;
H = window. innerHeight;
ResizeCheck ();
}
Function resizeCheck (){
If (w! = Window. innerWidth | h! = Window. innerHeight ){
Location. replace (location. href );
Return;
}
SetTimeout ("resizeCheck ()", 1000 );
}
Function back (){
DivMoveTo (d1, 200,50 );
DivMoveTo (d2, 250,75 );
DivMoveTo (d3, 75, 75 );
DivZIndex (d1, 1 );
DivZIndex (d2, 2 );
DivZIndex (d3, 3 );
DivBgColor (d1, '#555 ');
DivBgColor (d2, '#777 ');
DivBgColor (d3, '#999 ');
DivTxtColor (d1, '# fff ');
DivTxtColor (d2, '# fff ');
DivTxtColor (d3, '# fff ');
DivShow (d1 );
DivShow (d2 );
DivShow (d3 );
}
Function color (){
DivBgColor (d1, '# f02d2d ');
DivBgColor (d2, '# f040d1 ');
DivBgColor (d3, '#55afe0 ');
DivTxtColor (d1, '# fff ');
DivTxtColor (d2, '# fff ');
DivTxtColor (d3, '# fff ');
}
Function divMoveTo (d, x, y ){
D. style. pixelLeft = x;
D. style. pixelTop = y;
}
Function divMoveBy (d, dx, dy ){
D. style. pixelLeft + = dx;
D. style. pixelTop + = dy;
}
Function divShow (d ){
D. style. visibility = 'visable ';
}
Function divHide (d ){
D. style. visibility = 'ddd ';
}
Function divSizeTo (d, w, h ){
D. style. pixelWidth = w;
D. style. pixelHeight = h;
}
Function divSizeBy (d, dw, dh ){
D. style. pixelWidth + = dw;
D. style. pixelHeight + = dh;
}
Function divZIndex (d, z ){
D. style. zIndex = z;
}
Function divBgColor (d, c ){
D. style. background = c;
}
Function divTxtColor (d, c ){
D. style. color = c;
}
</Script>
</Head>
<Body id = "bodyId">
<Form name = "form1">
<H3> DHTML method basics-some simple DIV control BY 51js zdzhuo <P>
<Input type = "button" value = "Mobile d2" onclick = "divMoveBy (d2, 10, 10)"> <br>
<Input type = "button" value = "Move d3 to d2 (0, 0)" onclick = "divMoveTo (d3, 0, 0)"> <br>
<Input type = "button" value = "Move d3 to d2 (75, 75)" onclick = "divMoveTo (d3, 75)"> <br>
</P>
<P>
<Input type = "button" value = "Enlarge d1" onclick = "divSizeBy (d1, 15, 15)"> <br>
<Input type = "button" value = "zoom in d1" onclick = "divSizeBy (d1,-15,-15)"> <br>
</P>
<P>
<Input type = "button" value = "Hide d2" onclick = "divHide (d2)"> <br>
<Input type = "button" value = "display d2" onclick = "divShow (d2)"> <br>
</P>
<P>
<Input type = "button" value = "Priority: d1" onclick = "divZIndex (d1, 2); divZIndex (d2, 1)"> <br>
<Input type = "button" value = "d2" onclick = "divZIndex (d1, 1); divZIndex (d2, 2)"> <br>
</P>
<P>
<Input type = "button" value = "fill color" onclick = "color ()"> <br>
</P>
<P>
<Input type = "button" value = "Return default state" onclick = "back ()"> <br>
</P>
</Form>
<Div id = "d1">
<B> d1 </B>
</Div>
<Div id = "d2">
<B> d2 </B> <br>
D2 contains d3
<Div id = "d3">
<B> d3 </B> <br>
D3 is the child layer of d2
</Div>
</Div>
</Body>
</Html>