Javascript : exemples avec le code source

J - Modification d'un calque

D├ęplacement

 

Code

<html>
<head>
<script language="javascript">
function deplace(dx,dy) {
document.getElementById('calque').style.top
  = parseInt(document.getElementById('calque').style.top)+dy+'px';
document.getElementById('calque').style.left
  = parseInt(document.getElementById('calque').style.left)+dx+'px';
}
</script>
</head>
<body>
<div style="text-align:center">
<input type="button" value="&uArr;" onClick="deplace(0,-5)">
</div>
<div style="text-align:center">
<input type="button" value="&lArr;" onClick="deplace(-5,0)">
<input type="button" value="&dArr;" onClick="deplace(0,5)">
<input type="button" value="&rArr;" onClick="deplace(5,0)">
</div>
<div id="calque" style="position:absolute; height:20px; width:20px; background-color:#CC0000; left:445px; top:270px">&nbsp;</div>
</body>
</html>
Validé XHTML 1.1    Validé CSS