zepto兼容ie10的方法

原先的zepto,通过__proto__赋值,来使dom继承到$.fn方法,

无奈IE11之前的IE10,IE9不支持这种写法,

所以我们只能自己手动把方法添加到dom
// `$.zepto.Z` swaps out the prototype of the given `dom` array
// of nodes with `$.fn` and thus supplying all the Zepto functions
// to the array. Note that `__proto__` is not supported on Internet
// Explorer. This method can be overriden in plugins.
zepto.Z = function(dom, selector) {
dom = dom || []

// 支持ie10,主要是支持wp8
if(navigator.userAgent.indexOf(“MSIE 10″) > -1){
for(var func in $.fn){
dom[func] = $.fn[func];
}
}
else{
dom.__proto__ = $.fn
}

dom.selector = selector || ”
return dom
}


附:Zepto 1.0的默认兼容平台和浏览器如下:

桌面浏览器:

Safari 5+ (Mac, Win)
Chrome 5+ (Win, Mac, Linux, Chrome OS)
Mozilla Firefox 4+ (Win, Mac, Linux)
Opera 10+ (Win, Mac, Linux)
移动浏览器:

iOS 4+ Safari
Chrome for Android
Chrome for iOS
Android 2.2+ Browser
webOS 1.4.5+ Browser
BlackBerry Tablet OS 1.0.7+ Browser
Amazon Silk 1.0+
Firefox for Android
Firefox OS Browser
Practically any WebKit-based browsers/runtimes

参考链接:
http://www.cnblogs.com/samwu/p/3433117.html
http://www.36kr.com/p/201654.html

发表回复