Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<div id="box"></div>
</body>
</html>
 
#box{
  width: 400px;
  height: 400px;
  background: red;
}
body{
  display: flex;
  justify-content: center;
  align-items: center;
}
 
var rotate = 0;
var width = 400;
var element = document.getElementById('box');
function step(timestamp) {
    rotate += 4
    element.style.transform = `rotate(${rotate}deg)`;
    window.requestAnimationFrame(step);
}
function small(timestamp) {
    width = width - 1
    element.style.width = width + 'px';
    if (width <= 50) {
        window.requestAnimationFrame(big);
    } else {
        window.requestAnimationFrame(small);
    }
}
function big() {
    width = width + 1
    element.style.width = width + 'px';
    if (width >= 400) {
        window.requestAnimationFrame(small);
    } else {
        window.requestAnimationFrame(big);
    }
}
window.requestAnimationFrame(step);
window.requestAnimationFrame(small);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
hubingliangpro
0viewers