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

本文标签: javascriptDetect property of the transition endStack Overflow