<div id="block">click me</div>
#block{
position:absolute;
left: 50%;
top: 50%;
width: 100px;
height: 100px;
margin: -50px 0 0 -50px;
background: #0c8;
line-height: 100px;
text-align: center;
color: #fff;
cursor: pointer;
}
block.addEventListener('click', function(){
var self = this, startTime = Date.now(),
disX = 200, disY = 200,
duration = 1000 * Math.sqrt(2 * disY / 98);
//假设10px是1米,disY = 20米
requestAnimationFrame(function step(){
var p = Math.min(1.0, (Date.now() - startTime) / duration);
var tx = disX * p;
var ty = disY * p * p;
self.style.transform = 'translate('
+ tx + 'px' + ',' + ty +'px)';
if(p < 1.0) requestAnimationFrame(step);
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.