javascript implements a method to dynamically change the size of layers
- 2020-06-12 08:33:07
- OfStack
This article illustrates how javascript can dynamically change the size of layers. Share to everybody for everybody reference. Specific implementation methods are as follows:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Dynamically sets the size of the layer </title>
<style type="text/css">
.divMain
{
width:10px;
height:100px;
border-style:solid;
border-width:1px;
border-color:Green;
display:none;
}
</style>
<script type="text/javascript">
var setIntervalID;
function ZoomDiv() {
var divMain = document.getElementById("divMain");
divMain.style.width = "200px";
divMain.style.height = "200px";
}
function ShowDiv() {
setIntervalID = setInterval("inc()", 100);
}
function inc() {
var divMain = document.getElementById("divMain2");
//div Cannot set class, Otherwise, use divMain.style.width Of time and space
// Can only be set within elements style="width:10px;height:100px"
var oldWidth = divMain.style.width;
var oldHeight = divMain.style.height;
oldWidth = parseInt(oldWidth);
oldHeight = parseInt(oldHeight);
oldWidth += 1;
oldHeight += 1;
if (oldWidth >= 200) {
// Clearance timer
clearInterval(setIntervalID);
return;
}
divMain.style.width = oldWidth + "px";
divMain.style.height = oldHeight + "px";
}
</script>
</head>
<body>
<input type="button" value=" Enlarge layer " onclick="ZoomDiv()" />
<input type="button" value=" Dynamic amplification layer " onclick="ShowDiv()" />
<div id="divMain" class="divMain">
case : Follow the mouse to fly the picture. prompt : Mouse movement of events when onmousemove, through
window.event the clientX,clientY Property gets the mouse position
</div>
<!-- I can't set it here class, Otherwise, use divMain.style.width Of time and space -->
<div id="divMain2" style="width:10px;height:100px;background-color:Red;">
case : Follow the mouse to fly the picture. prompt : Mouse movement of events when onmousemove, through
window.event the clientX,clientY Property gets the mouse position
</div>
</body>
</html>
Hopefully, this article has been helpful in your javascript programming.