Zepto回退到jQuery [英] Zepto fallback to jQuery

查看:106
本文介绍了Zepto回退到jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ZeptoJS作为我的网络应用程序,但如果浏览器不支持Zepto,我想回到jQuery。由于IE是目前唯一不支持的主要浏览器,我很想检测IE:

I'm using ZeptoJS for my web app, but I'd like to fall back to jQuery if the browser doesn't support Zepto. Since IE is the only major browser not supported at the moment, I'm tempted to detect IE:

if(navigator.appName == 'Microsoft Internet Explorer'){
    // load jquery
} else {
    // load zepto
}

但我更愿意特别检测Zepto支持并在其他情况下使用jQuery。是否有一种功能检测方法可以做到这一点?

but I'd prefer to specificly detect Zepto support and use jQuery in other cases. Is there a feature detection way to do this?

推荐答案

这可能是一个疯狂的想法(我不确定Zepto是否会甚至在不受支持的浏览器上加载,但是如何使用Zepto自己的浏览器检测来查看它是否在不受支持的浏览器上?

This might be a crazy idea (I'm not sure if Zepto will even load on an unsupported browser), but what about using Zepto's own browser detection to see if it's on an unsupported browser?

$.os.ios      // => true if running on Apple iOS
$.os.android  // => true if running on Android
$.os.webos    // => true if running on HP/Palm WebOS
$.os.touchpad // => true if running on a HP TouchPad
$.os.version  // => string with version number, "4.0", "3.1.1", "2.1", etc.
$.os.iphone   // => true if running on iPhone
$.os.ipad     // => true if running on iPad
$.os.blackberry // => true if running on BlackBerry

也许您可以执行以下操作:

Maybe you could do something like this:

var isSupported = false;
for (os in $.os) {
    if ($.os[os] == true) { isSupported = true; }
}

这不会捕获chrome / firefox,它可以与Zepto一起使用,但它确实符合Zepto团队对该事物的意图,这可能会或可能不会更好。

This won't catch chrome/firefox, which work fine with Zepto, but it does match the Zepto team's intentions for the thing, which may or may not be better.

这篇关于Zepto回退到jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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