使用javascript(而不使用modernizr)检测CSS转换? [英] Detect css transitions using javascript (and without modernizr)?

查看:112
本文介绍了使用javascript(而不使用modernizr)检测CSS转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检测浏览器支持使用javascript(而不使用modernizr)的CSS转换?

How would I detect that a browser supports css transitions using javascript (and without using modernizr)?

推荐答案

这个。基本上只是看看CSS 转换属性是否已定义:

Perhaps something like this. Basically it's just looking to see if the CSS transition property has been defined:

function supportsTransitions() {
    var b = document.body || document.documentElement,
        s = b.style,
        p = 'transition';

    if (typeof s[p] == 'string') { return true; }

    // Tests for vendor specific prop
    var v = ['Moz', 'webkit', 'Webkit', 'Khtml', 'O', 'ms'];
    p = p.charAt(0).toUpperCase() + p.substr(1);

    for (var i=0; i<v.length; i++) {
        if (typeof s[v[i] + p] == 'string') { return true; }
    }

    return false;
}

改编自这个要点。所有信用都到那里。

Adapted from this gist. All credit goes there.

这篇关于使用javascript(而不使用modernizr)检测CSS转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆