矩形描画
|
<html>
<body>
<div id="rect"></rect>
<script type="text/javascript">
document.addEventListener('mousedown', mousedown, true);
document.addEventListener('mouseup', mouseup, true);
document.addEventListener('mousemove', mousemove, true);
var rect = document.getElementById('rect');
var down = false;
function mousedown(){ down = true; }
function mouseup(){ down = false; }
function mousemove(e){
if(down){
rect.style.backgroundColor = "#ffff00";
rect.style.height = e.pageY;
rect.style.width = e.pageX;
}
}
</script>
</body>
</html>