3

I have a transition set:

element.one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function(){ 
    scrollActive = false;
}).css({
    '-webkit-transform': '' + prop + '(' + value + 'px)',
    '-ms-transform': '' + prop + '(' + value + 'px)',
    'transform': '' + prop + '(' + value + 'px)'
});

and in CSS:

.element {
    transition: transform ease-in-out 0.3s;
}

If I don't have transition set in CSS, the transitionend event will never fire.

Is there a way to check if element has transition set?

2

2 Answers 2

5

Try to use getComputedStyle().getPropertyValue() here. The default value of transition is all 0s ease 0s, if not applied in an element

var elem = document.querySelector(".element");
var style = window.getComputedStyle(elem, null).getPropertyValue("transition");
if (style === "all 0s ease 0s") {
  console.log("Not set");
} else {
  console.log("Set");
}
.element {
  transition: transform ease-in-out 0.3s;
}
<div class="element"></div>

Sign up to request clarification or add additional context in comments.

Comments

2

Window.getComputedStyle()

 const styles = window.getComputedStyle(element);

 const hasTransition = styles.transition !== "all 0s ease 0s";

https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

The Window.getComputedStyle() method returns an object that reports the values of all CSS properties of an element after applying active stylesheets and resolving any basic computation those values may contain. Individual CSS property values are accessed through APIs provided by the object or by simply indexing with CSS property names.

WARNING: This function is very expensive to calculate.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.