48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
/**
|
|
* This will store the property that the current
|
|
* browser uses for transitionDuration
|
|
*/
|
|
var property;
|
|
|
|
/**
|
|
* The properties we'll check on an element
|
|
* to determine if it actually has transitions
|
|
* We use duration as this is the only property
|
|
* needed to technically have transitions
|
|
* @type {Array}
|
|
*/
|
|
var types = [
|
|
"transitionDuration",
|
|
"MozTransitionDuration",
|
|
"webkitTransitionDuration"
|
|
];
|
|
|
|
/**
|
|
* Determine the correct property for this browser
|
|
* just once so we done need to check every time
|
|
*/
|
|
while(types.length) {
|
|
var type = types.shift();
|
|
if(type in document.body.style) {
|
|
property = type;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Determine if the browser supports transitions or
|
|
* if an element has transitions at all.
|
|
* @param {Element} el Optional. Returns browser support if not included
|
|
* @return {Boolean}
|
|
*/
|
|
function hasTransitions(el){
|
|
if(!property) {
|
|
return false; // No browser support for transitions
|
|
}
|
|
if(!el) {
|
|
return property != null; // We just want to know if browsers support it
|
|
}
|
|
var duration = getComputedStyle(el)[property];
|
|
return duration !== "" && parseFloat(duration) !== 0; // Does this element have transitions?
|
|
}
|
|
|
|
module.exports = hasTransitions; |