<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#body{
position: absolute;
width: 300px;
height: 300px;
top:100px ;
}
#a{
position: absolute;
top:140px ;
width: 300px;
height: 20px;
background-color: green;
transform: rotate(0deg);
}
#b{
position: absolute;
left:140px;
width: 20px;
height: 300px;
background-color: green;
transform: rotate(0deg);
}
</style>
<script>
var i = 0;
var xz_id;
var sd = 10;
var ids = new Array();
window.onload = function(){
xz = document.getElementById("xz");
a = document.getElementById("body");
mess = document.getElementById("mess");
xz.onclick = function(){
id = setInterval("xuanzhuan()",10);
ids.push(id);
mess.innerHTML = ids.length;
}
document.getElementById("tz").onclick = function(){
clearInterval(ids[ids.length-1]);
ids.pop();
mess.innerHTML = ids.length;
}
}
function xuanzhuan(){
if(i>360){
i=0;
}else{
i++;
}
var s = "rotate("+i+"deg)";
a.style.transform = s;
}
</script>
</head>
<body>
<button id="xz">加速</button>
<button id="tz">减速</button><br />
<span id="mess"></span>
<div id="body">
<div id="a"></div>
<div id="b"></div>
</div>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#body{
position: absolute;
width: 300px;
height: 300px;
top:100px ;
}
#a{
position: absolute;
top:140px ;
width: 300px;
height: 20px;
background-color: green;
transform: rotate(0deg);
}
#b{
position: absolute;
left:140px;
width: 20px;
height: 300px;
background-color: green;
transform: rotate(0deg);
}
</style>
<script>
var i = 0;
var xz_id;
var sd = 10;
var ids = new Array();
window.onload = function(){
xz = document.getElementById("xz");
a = document.getElementById("body");
mess = document.getElementById("mess");
xz.onclick = function(){
id = setInterval("xuanzhuan()",10);
ids.push(id);
mess.innerHTML = ids.length;
}
document.getElementById("tz").onclick = function(){
clearInterval(ids[ids.length-1]);
ids.pop();
mess.innerHTML = ids.length;
}
}
function xuanzhuan(){
if(i>360){
i=0;
}else{
i++;
}
var s = "rotate("+i+"deg)";
a.style.transform = s;
}
</script>
</head>
<body>
<button id="xz">加速</button>
<button id="tz">减速</button><br />
<span id="mess"></span>
<div id="body">
<div id="a"></div>
<div id="b"></div>
</div>
</body>
</html>