style part
.aa{position:absolute;transition:top 2s;}
html part
<div id="ele" class="aa"></div>
js part
var ele=document.getElementById("ele")
ele.onclick=function(){
ele.style.top=0
//ele.style.top=100+"px"setTimeouttop0100
setTimeout(function(){
ele.style.top=100+"px"
},0)
}
online preview address
http://jsbin.com/pucedelowa/e.
now there is a doubt, why only put ele.style.top=100+"px" in seTimeout, click on the text will have the animation effect of transition?
are there any other functions that can achieve the same effect as setTimeout?