LoginSignup
0
1

More than 5 years have passed since last update.

ベンダープレフィックスがあるか確認するやつ

Last updated at Posted at 2015-11-20

ベンダープレフィックスが必要そうなプロパティで使用。
有りでも無しでもイイからとりあえず先に見つかったやつを返す。
どっちもなければ、動作はしないけど無しを返す。null とか返すとエラーになっちゃうから。
どっちもなければ、元のプロパティを返す。

const getPrefixProperty = (_property) => {
  const decs_    = getComputedStyle(document.head, '');
  const prefixs_ = [ '-webkit-', '-moz-', '-ms-', '-o-' ];

  let property_ = _property;

  if(!decs_[_property]) {
    prefixs_.forEach((_prefix) => {
      const p_ = _prefix + _property;
      if(decs_[p_]) {
        property_ = p_;
        return false;
      }
    });
  }

  return property_;
};

// 実行
getPrefixProperty('transition');

変更履歴

  • CoffeeScript -> ES2016
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1