代码:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#layer a img{
width: 150px;
height: 150px;
}
div#layer{
position: absolute;
left: 15px;
top: 30px;
}
</style>
</head>
<body>
<div id="layer">
<a href="#"><img src="./an.jpg" /></a>
</div>
<script>
window.οnlοad=move;
function move(){
document.getElementById("layer").style.left=Math.random()*50+"px";
document.getElementById("layer").style.top=Math.random()*60+"px";
setInterval("move()",1000);
}
</script>
</body>
</html>
图片:
小结:
用js脚本来控制css的值