0

I'm trying add animation-duration css3 property respective of height and width of grid. I made it using this code div.style.animationDuration. It works good for me.

my concern is how to add vendor prefix css3 property for animation-duration in js like -ms-animation-duration

1
  • Latest browser version require no prefix except Safari with -webkit. I don't think MS ever prefixed this. Commented Mar 3, 2016 at 13:55

2 Answers 2

1

Generally vendor prefixes in javascript for css are as follows:

  1. moz for Mozilla Firefox

  2. webkit for Google Chrome , Apple Safari, and other webkit-based browsers

  3. ms for Microsoft Internet Explorer

  4. o for Opera

    Hence you can replace div.style.animationDuration with div.style.webkitAnimationDuration

To deal with this problem in general you can write a method

function setVendorCss(element, property, value) {
  element.style["webkit" + property] = value;
  element.style["moz" + property] = value;
  element.style["ms" + property] = value;
  element.style["o" + property] = value;
}

Read more here https://www.kirupa.com/html5/vendor_prefixes_javascript.htm

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

1 Comment

Shouldn't it be webkitAnimationDuration with an upper-case "A"?
0

Instead of selecting the element like so:

element.style.color = 'red';
element.style.fontSize = '2em';

Try:

element.style.cssText = 'color: red; font-size: 2em';

style.cssText is useful for adding multiple styles at a time, even the trickier ones that require prefixes.

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.