summaryrefslogtreecommitdiff
path: root/src/CSSUtil.js
blob: c4172b86095ea0221669cf7472ee87702d23b1ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * Created by Victor Häggqvist on 1/12/16.
 */

export class CSSUtil {

    /**
     * transion need to be set on property
     *
     * using key-value dont work
     *
     * @param ele DOMElement
     * @param value
     */
    static setTransitionProperty(ele, value) {
        let style = ele.style;
        if (style.transition === '')  {
            style.transition = value;
            return;
        }
        if (style.WebkitTransition === '') {
            style.WebkitTransition = value;
            return;
        }
        if (style.MozTransition === '') {
            style.MozTransition = value;
            return;
        }
        if (style.OTransition === '') {
            style.OTransition = value;
        }
    }

    static cssTransitionSupport() {
        let d = document.body || document.documentElement, s = d.style;
        if (s.WebkitTransition === '')
            return '-webkit-';
        if (s.MozTransition === '')
            return '-moz-';
        if (s.OTransition === '')
            return '-o-';
        if (s.transition === '')
            return '';
        return false;
    }

    static cssTransitionTranslateX(element, positionX, speed) {
        let options = {};
        let prefix = CSSUtil.cssTransitionSupport();
        element.style[prefix + 'transform'] = 'translateX(' + positionX + ')';
        element.style[prefix + 'transition'] = prefix + 'transform ' + speed + 's linear';
        //element.style = Object.assign(options, element.style);
    }

}
CSSUtil.isCssTransitionSupport = CSSUtil.cssTransitionSupport() !== false;