<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{width:100px;height:100px;background:red; transition:1s width;}
</style>
</head>
<body>
<div class="box" id="box"></div>
<script>
var oBox=document.getElementById("box");
oBox.onclick=function()
{
this.style.width=this.offsetWidth+100+"px";
};
window.addEnd(oBox,function(){
console.log(this);//这里的this按照网上的说法,谁调用就是指谁;在addEnd(oBox,function(){})之前我写上window,说明是window调用了这个函数的,但function(){}中的this不是指的window,就搞不懂了,前来求证
this.style.width=this.offsetWidth+100+"px";
});
function addEnd(obj,fn)
{
obj.addEventListener('WebkitTransitionEnd',fn,false);
obj.addEventListener('transitionend',fn,false);
}
</script>
</body>
</html>
相关分类