javascript - Detect property of the transition end - Stack Overflow

I sought to detect the property of which the transition is pleted in the case of several transitions of

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
Add a ment  | 

1 Answer 1

Reset to default 6

You 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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745157649a4614219.html

相关推荐

  • javascript - Detect property of the transition end - Stack Overflow

    I sought to detect the property of which the transition is pleted in the case of several transitions of

    10小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信