Modernizr.js 是否有助于在旧版浏览器上显示 css 3 和 html 5?如何?

发布于 2024-12-20 21:32:11 字数 123 浏览 4 评论 0 原文

我在网页中使用了 css 3、html 5,我想使用 Modernizr 来显示一些 html5 属性和一些 css 3,例如旧浏览器上的 border-radius,
Modernizr 在这方面有帮助吗?以及如何运行它。

I used css 3, html 5 in a web page and I want to use Modernizr to show some html5 attributes and some css 3 such as border-radius on old browsers,
Does Modernizr help in this and how run it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

聊慰 2024-12-27 21:32:11

Modernizr 只会帮助您检测某些功能,因此您必须自己添加 JS 修复。

如果您想要使用预打包的解决方案,这可能会有所帮助: https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills

在您的情况下,这可能是要走的路:http://css3pie.com/

Modernizr will only help you detect certain features, so you'll have to add the JS fixes yourself.

In case you want to go for a pre-packaged solution this might be of help: https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills

In your case this might be the way to go: http://css3pie.com/

以歌曲疗慰 2024-12-27 21:32:11

Modernizr 不会向除 HTML5 Shiv 之外的旧版浏览器添加缺失的功能,以便您可以使用 HTML5 中的新语义元素并设置其样式。其他答案已经显示了一些填充选项,但是,我建议您重新考虑以这种方式向旧浏览器添加纯粹的视觉效果,例如 border-radius 。 Polyfill 会降低旧版浏览器的速度(有时非常显着),并使这些用户的整体体验更差

Modernizr doesn’t add missing functionality to older browsers other than the HTML5 Shiv so that you can use and style the new semantic elements from HTML5. The other answers already show some polyfill options, however, I recommend you reconsider adding purely-visual effects like border-radius to older browsers that way. Polyfills slow the older browsers down (sometimes very significantly) and make the overall experience much worse for those users.

陪你到最终 2024-12-27 21:32:11

您可以使用modernizr 来检测可用的内容,例如圆角。如果不是,您可以通过 Modernizr API 优雅地降级,甚至使用插件来模拟该功能。

<script type="text/javascript">
    Modernizr.load({
        test: Modernizr.borderradius,
        nope: 'script/jquery.corner.js',
        callback: function () {
            $('article').corner();
            $('figure').corner();
        }
    });
</script>

代码片段取自 http://blogs.msdn.com/b/jennifer/archive/2011/08/04/html5-part-4-using-html5-while-retaining-support-for-older-browsers。 ASPX

You can use modernizr to detect what's available, e.g. rounded corners. If it's not, you can degrade gracefully via the modernizr API, or even use a plug-in to smoke and mirrors the feature.

<script type="text/javascript">
    Modernizr.load({
        test: Modernizr.borderradius,
        nope: 'script/jquery.corner.js',
        callback: function () {
            $('article').corner();
            $('figure').corner();
        }
    });
</script>

Code snippet taken from http://blogs.msdn.com/b/jennifer/archive/2011/08/04/html5-part-4-using-html5-while-retaining-support-for-older-browsers.aspx

冰火雁神 2024-12-27 21:32:11

Modernizr 对 CSS3 没有帮助。 来实现此目的,但它有一些您需要阅读的跨域问题。)

(您可以使用 Selectivizr 确实有 IEPP for HTML5 shim support 并且它附带 <一个href="http://www.modernizr.com/docs/#load" rel="nofollow">YepNope.js as Modernizr.load,这是一个很棒的 Polyfills 加载器机制,因此您可以加载自己的支持对于较旧的浏览器。这将帮助您放弃对 patternplaceholder 等属性的支持,而不会超载对其具有本机支持的浏览器。

Modernizr does not help with CSS3. (You could use Selectivizr for this, but it has some cross-domain issues you'll want to read about.)

Modernizr does have IEPP for HTML5 shim support and it comes with YepNope.js as Modernizr.load, which is a great polyfills loader mechanism so you can load your own support for older browsers. That will help you drop in support for attributes like pattern and placeholder without overloading browsers that have native support for it.

三生池水覆流年 2024-12-27 21:32:11

Modernizr 内部使用与您在其他情况下使用的相同的 JS 代码。
例如,如果您想使用本机方式检查“输入”占位符支持,您可以使用;

function support_input_placeholder() {  
    var i = document.createElement('input');
    return 'placeholder' in i;
}

虽然 Modernizr 的检查方式就像

function support_input_modern() {   
    if (Modernizr.input.placeholder) 
        return true;
    else
        return false;
}

但是上面的代码具有与本机方式相同的内部工作...

所以理想情况下,我更喜欢本机方式来进行更简单和更少的检查...

仅对于非常复杂的事情,应该我们追求现代化

Modernizr internally uses the same JS code that you would use otherwise..
e.g. If you want to check for "input" placeholder support, using Native way, you would use;

function support_input_placeholder() {  
    var i = document.createElement('input');
    return 'placeholder' in i;
}

While the Modernizr way to check would be like

function support_input_modern() {   
    if (Modernizr.input.placeholder) 
        return true;
    else
        return false;
}

But the above code has the same internal working as the native way...

So ideally, I would prefer native way for simpler and lesser amount of checking...

Only for very complex things, should we go for Modernizr

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文