导航:首页 > 编程语言 > modernizrjs使用

modernizrjs使用

发布时间:2025-07-27 02:38:13

① HTML5中Modernizr类库是做什么用的具体怎么使用

Modernizr 是一个用来检测浏览器功能支持情况的 JavaScript 库。通过这个库我们可以检测不同的浏览器对于HTML5特性的支持情况。使用Modernizr类库和使用其他第三方类库的方法是一样的它分为一下几个步骤“
1、在官网上下载Modernizr类库。modernizr官网:https://modernizr.com/
2、通过JavaSctipt标签引入Modernizr类库
3、通过具体的代码实现对HTML特性的检测。
这里我们写了一个非常简单的例子来检测浏览器是否支持HTML5中的Canvas API,示例如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>通过Modernizr检测HTML5特性</title>
</head>
<body>
<article>
<h1>通过Modernizr检测HTML5特性</h1>
</article>
<div id="result-stub">
<span id="msg" style="color:red;"></span>
</div>

<script >
window.onload = function() {
//通过Modernizr.对浏览器canvas功能进行检测
if (Modernizr.canvas) {
$('#msg').text('本浏览器支持Canvas API');
}else{
$('#msg').text('本浏览器不支持Canvas API');
}
}
</script>
//引入modernizr库和jquery库
<script src="../js/jquery.js"></script>
<script src="../js/modernizr.js"></script>
</body>
</html>
这些内容关乎到HTML5中第三方类库的使用,关于HTML5的相关知识我们建议你可以去一个叫做秒秒学的教程网站上看看。

② 如何使用js-polyfills

Polyfills是一种保证使用现代代码的绝佳办法,同时还能支持旧版浏览器。但是目前polyfills使用起来很困难,因此我们开发了一种全新的服务以便简化其使用方法。在此,邀请读者使用并改进它。

挑战

下面是我们正在尝试解决的一些问题:

③ 有没有能兼容各浏览器的前端开发框架

想完全兼容各种浏览器,尤其是各个版本的前端开发框架,目前几乎没有。

跨浏览器开发应该使用的技巧:

  1. modernizr.js 特性检测器,有就使用原生,没有就加载polyfill;

  2. polyfill/shim 向后兼容的浏览器的js补丁,一般和modernizr一起用;

  3. jshint.js js语法检测器;

  4. Boilerplate 开发的最佳实践的初始模板;

  5. 阅读第三方库关于最低版本支持;

  6. 使用js单元测试,测试目标浏览器;

  7. Responsive Design (针对屏幕大小);

  8. normalize.css 统一浏览器基本元素的风格;

跨浏览器兼容问题,过去现在都有,以后会更麻烦,所以这个问题在项目开始前,就必须确定下来最低支持的版本是什么,然后设计一个对应兼容方案。不要等开发完毕了,才告知要必须兼容其他的,那整体的修改量就很大了。

④ modernizr.custom.js 插件是干什么用的

Modernizr是一个开源的JS库,它使得那些基于访客浏览器的不同(指对新标准支持性的差专异)而开发不同级别体验的设属计师的工作变得更为简单。它使得设计师可以在支持HTML5和CSS3的浏览器中充分利用HTML5和CSS3的特性进行开发,同时又不会牺牲其他不支持这些新技术的浏览器的控制。

当你在网页中嵌入Modernizr的脚本时,它会检测当前浏览器是否支持CSS3的特性,比如 @font-face、border-radius、 border-image、box-shadow、rgba() 等,同时也会检测是否支持HTML5的
特性——比如audio、video、本地储存、和新的
<input>标签的类型和属性等。在获取到这些信息的基础上,你可以在那些支持这些功能的浏览器上使用它们,来决定是否创建一个基于JS的
fallback,或者对那些不支持的浏览器进行简单的优雅降级。另外,Modernizr还可以令IE支持对HTML5的元素应用CSS样式,这样开发者就可以立即使用这些更富有语义化的标签了。

⑤ 2020JS-3D是测量什么的

Modernizr?是用于检测浏览器对?HTML5?和?CSS3?支持的?JavaScript?库这句的意思是检测浏览器是否支持专?CSS3?的?3D?transform(例如属?matrix3d,?translate3d?等等).transform { -webkit-transform: translate3d(60,0,0); -moz-transform: translate3d(60,0,0); -o-transform: translate3d(60,0,0); -ms-transform: translate3d(60,0,0); transform: translate3d(60,0,0);}// 如果浏览器支持 CSS3 3D transformif(Modernizr.csstransforms3d) { // 添加 transform class $(;my_div;).addClass(;transform;);}

⑥ 怎么让aos.js低版本不执行

是报这样的错吧: undefined is not a function;
因为1.9之后移除了toggle。
以下来自网络:

jQuery 1.9较之前版本的变化,主要介绍移除方法的替代方法:.browser、.live、.die、.sub、.toggle

简介:

本文档是一次调研总结,直接贴过来的,没有作背景铺垫修改。这是一个关于jQuery1.9较之前版本变化的调研,完了之后,总结了这么一个对于“jQuery 1.9移除方法的替代总结”的文档,不一定是最优的解决方案,但我所提到的方法绝对可行。

本文档总结了一些jQuery 1.9较之前版本的变化(原文:http://jquery.com/upgrade-guide/1.9/),看官方Blog,JQuery2.0已经出到了Beta2 Released版本,并且不再支持IE 6/7/8.

以下为涉及到Gaia 1.0的几个变化:

jQuery.browser()

jQuery.browser() removed

The jQuery.browser() method has been deprecated since
jQuery 1.3 and is removed in 1.9. If needed, it is available as part of
the jQuery Migrate plugin. We recommend using feature detection with a
library such as Modernizr.

这里给出的是用Modernizr(一个利用JS和CSS来检测浏览器所支持功能的小工具)来检测浏览器所支持功能,其实官网还给出了另一种解决方案:

Because $.browser uses navigator.userAgent
to determine the platform, it is vulnerable to spoofing by the user or
misrepresentation by the browser itself. It is always best to avoid
browser-specific code entirely where possible. The$.support property is available for detection of support for particular features rather than relying on $.browser.

Gaia1.0中用到JQuery.browser()方法的为:

$.browser.msie && $.browser.version <= 8

作为常用的两种方法,

JQuery.browser.mise(如果是IE则返回true)可以用JQuery.support.boxModel(如果IE浏览器是QuirksMode方式运行,则返回false)代替;

jQuery.browser.version <= 8可以用jQuery. support.leadingWhitespace(判断浏览器是否为IE 6~8版本)代替;

这样上述语句可以改为:

$.support.boxModel && $.support.leadingWhitespace

另外,jQuery.support.objectAll可判断浏览器是否为IE 7~8版本。由于jQuer2.0不再支持IE9之前的版本,日后升级还需根据官方推荐判断浏览器类型及版本加载不同的jQuery。如官方推荐方式;

<!--[if lt IE 9]>

<script src='jquery-1.9.0.js'></script>

<![endif]-->

<!--[if gte IE 9]>

<script src='jquery-2.0.0.js'></script>

<![endif]-->

如果必须要继续使用jQuery.browser()可以添加“jquery-browser”插件,但我没有测试该插件。

.live()

link .live() removed

The .live() method has been deprecated since jQuery 1.7 and has been
removed in 1.9. We recommend upgrading code to use the .on() method
instead. To exactly match $("a.foo").live("click", fn), for example, you
can write $(document).on("click", "a.foo", fn). For more information,
see the .on() documentation. In the meantime, the jQuery Migrate plugin can be used to restore the .live() functionality.

.live()方法在1.9中移除,@ZPS在邮件中已经告知过大家。对于.live()方法的移除,升级比较简单,仅仅是将“.live()”替换为“.on()”。

.die()

.die() removed

The .die() method has been deprecated since jQuery 1.7 and has been
removed in 1.9. We recommend upgrading code to use the .off() method
instead. To exactly match $("a.foo").die("click"), for example, you can
write $(document).off("click", "a.foo"). For more information, see the .off() documentation. In the meantime, the jQuery Migrate plugin can be used to restore the .die() functionality.

相对于“.live()”方法的移除,“.die()”方法也从1.9中移除,取而代之的是“.off()”方法。正如在1.9之前,很多人只关注
过“.live()”方法,却不知道还有个“.die()”方法,或许还会有Coder不知道如何去掉.on()添加的事件,其实就是用“.off()”
进行删除添加的事件。

jQuery.sub()

jQuery.sub() removed

The jQuery.sub() method has been moved to the jQuery Migrate plugin.
The number of use cases where it proved valuable were not enough to
justify keeping it in core. The jQuery Migrate plugin adds back this
functionality.

.sub()方法可以创建一个新的jQuery副本而不影响原有的jQuery对象,我对该方法的理解是:其实.sub()方法就是增加或重写jQuery的方法或创建新plugin,有待讨论。

从上面升级指南上来看,.sub()方法并没有被removed,而是被moved到其他plugin,所以应该是还可以用的,只要引用相应的plugin。

官方给出的使用.sub()的两个特定情况:一是在不改变原有方法的前提下提供一种简单的重写jQuery方法的途径,二是帮助用户解决jQuery plugin封装和基本命名空间。翻译晦涩,大家请看原文:

There are two specific use cases for which jQuery.sub() was created.
The first was for providing a painless way of overriding jQuery methods
without completely destroying the original methods and another was for
helping to do encapsulation and basic namespacing for jQuery plugins.

.toggle(function, function, … )

link .toggle(function, function, ... ) removed

This is the "click an element to run the specified functions"
signature of .toggle(). It should not be confused with the "change the
visibility of an element" of .toggle() which is not deprecated. The
former is being removed to rece confusion and improve the potential
for molarity in the library. The jQuery Migrate plugin can be used to
restore the functionality.

需要注意的是该.toggle()是“绑定两个或多个处理程序,在点击时循环执行”;另一个.toggle()仍然存在,它是“控制相应组件的显示和隐藏”;中文晦涩,官方对此二方法的说明如下:

Categories: Deprecated > Deprecated 1.8 | Events > Mouse Events

.toggle(handler(eventObject), handler(eventObject) [,handler(eventObject)])

Returns:jQuery

version deprecated: 1.8, removed: 1.9

Description:Bind two or more handlers to the matched elements, to be executed on alternate clicks.

Categories: Effects > Basics

.toggle( [ration ] [, complete ] )

Returns:jQuery

Description:Display or hide the matched elements.

这个变化值得注意。对于删除的这个“.toggle()”方法,官方没有给出升级措施,但我发现一个方法名和描述都比较相似的方法“.trigger()”,不知道可不可以替代,还请大家赐教。

另外,国外有论坛提到“jQuery Migrate Plugin”插件,可以使用该插件检测在jQuery 1.9 或2.0中哪些功能已经启用或移除。我还没有学习到,大家参看项目README吧。(谷歌这个插件,全是E文;网络这个插件,过半是E文)

阅读全文

与modernizrjs使用相关的资料

热点内容
什么是总体数据 浏览:259
网络是如何入户到家的 浏览:498
财联社的看涨数据是怎么来的 浏览:87
js控制打开网页后关机 浏览:824
朗读者app会员怎么下载 浏览:906
mina视频教程 浏览:53
excel经典教程视频 浏览:161
小松焊接机器人如何编程 浏览:682
java数字加密保持位数不变 浏览:84
错误代码080004002不支持此接口 浏览:590
诛仙碧瑶24升级 浏览:548
cad编辑器在哪个文件里 浏览:153
微信彩色名字怎么设置 浏览:60
交行app我的管家怎么开通 浏览:925
电脑文件怎么改雷电格式 浏览:623
电脑管家粉碎文件 浏览:16
网上怎么查看自家的网络 浏览:687
酒店网站如何找客户 浏览:979
微信网页版上保存的文件在哪找 浏览:102
凝思路由配置文件 浏览:180

友情链接