html:
<div class="wrap">
<div class="line"></div>
</div>
scss:
.wrap{
width: 400px;
height: 200px;
border: 1px solid;
margin: 0 auto;
.line{
position: relative;
margin-top: 50px;
margin-left: 50px;
width: 200px;
height: 4px;
background-color: blue;
&::before{
position: absolute;
left: 0;
top: 0;
content: '';
width: 100%;
height: 4px;
background-color: red;
transform: scaleX(0);
transform-origin: left top;
}
}
&:hover{
.line{
transform: translate3d(0, 0, 0) scaleX(.2);
transition: .6s;
}
.line::before{
transform: scaleX(1);
transition: .4s .6s;
}
}
}
js:
var line = document.querySelector('.line')
line.addEventListener('transitionend', function () {
alert(000)
}, false)
我想在.line:before->transition
结束后,再绑定回调
上面我直接绑定在line
上时,会回调两次,本身调用一次,伪元素再调用一次
我只想伪元素调用,本身不调用该怎么做?
(不想把伪元素替换成子元素)
打印了下
event
对象,发现event
对象有一个属性为pseudoElement
属性,所以你上面的代码可以这样写。演示的demo地址: http://codepen.io/jackpan/pen...