admin管理员组文章数量:1415467
I sought to detect the property of which the transition is pleted in the case of several transitions of the same element with different delay, like:
var cssTransitionEnd = 'webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend';
$('div').on(cssTransitionEnd, function(e) {
var borderColorEnd, backgroundColorEnd;
// Detect if this is border or background who ended ?
if(borderColorEnd) {
}
if(backgroundColorEnd) {
}
});
div {
width: 200px;
height: 200px;
background-color: red;
border: 4px solid yellow;
transition: border-color 1s, background-color 2s;
}
div:hover {
border-color: green;
background-color: blue;
}
<script src=".1.1/jquery.min.js"></script>
<div></div>
I sought to detect the property of which the transition is pleted in the case of several transitions of the same element with different delay, like:
var cssTransitionEnd = 'webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend';
$('div').on(cssTransitionEnd, function(e) {
var borderColorEnd, backgroundColorEnd;
// Detect if this is border or background who ended ?
if(borderColorEnd) {
}
if(backgroundColorEnd) {
}
});
div {
width: 200px;
height: 200px;
background-color: red;
border: 4px solid yellow;
transition: border-color 1s, background-color 2s;
}
div:hover {
border-color: green;
background-color: blue;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
Share
Improve this question
edited Aug 7, 2015 at 15:02
Harry
89.9k26 gold badges214 silver badges223 bronze badges
asked Aug 7, 2015 at 12:28
Pik_atPik_at
1,4579 silver badges14 bronze badges
1 Answer
Reset to default 6You can use the propertyName
property that es with the transtionend
event to find the name of the property whose transition
has ended.
One thing to note with this property is that it will not return the shorthand property names. Instead it will return the following longhand names for the border-color
property:
border-left-color
border-right-color
border-top-color
border-bottom-color
Note: For some reason, accessing the propertyName
property of the JS event object does not seem to work on Firefox (but works on Chrome). Using jQuery's event object instead of it seems to work as expected. Can only assume that there is some browser inconsistencies that jQuery does a good job of solving for us.
var cssTransitionEnd = 'webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend';
$('div').on(cssTransitionEnd, function(event) {
/* Just to make the output obvious :) */
$('div').html($('div').html() + event.originalEvent.propertyName + '<br>');
});
div {
width: 200px;
height: 200px;
background-color: red;
border: 4px solid yellow;
transition: border-color 1s, background-color 2s;
}
div:hover {
border-color: green;
background-color: blue;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
本文标签: javascriptDetect property of the transition endStack Overflow
版权声明:本文标题:javascript - Detect property of the transition end - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745157647a2645270.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论