繁体   English   中英

jQuery功能检测-如何实现此功能?

[英]jquery feature detection - how can I implement this?

我需要防止IE识别此插件中的fadeIn / Out效果。 如何向其中添加一行jquery功能检测代码:

$(function() {

var newHash      = "",
    $mainContent = $("#main-content"),
    $pageWrap    = $("#page-wrap"),
    baseHeight   = 0,
    $el;



$("nav#footer").delegate("a", "click", function() {
    window.location.hash = $(this).attr("href");
    return false;
});

$(window).bind('hashchange', function(){

    newHash = window.location.hash.substring(1);

    if (newHash) {
        $mainContent
            .find("#guts")
            .fadeOut(200, function() {
                $mainContent.show().load(newHash + " #guts", function() {
                    $mainContent.fadeIn(200, function() {
                    });
                    $("nav#footer a").removeClass("current");
                    $("nav#footer a[href="+newHash+"]").addClass("current");
                });
            });
    };

});

$(window).trigger('hashchange');

});

我有一些像

var FADE_TIME = 500; if(!($.support.opacity)) { FADE_TIME = 0}

$('element').fadeOut(FADE_TIME)

我应该在代码中的什么地方添加? 有人可以帮助我使这个工作真正吗?

无法弄清楚为什么有人不只是编辑代码并回答问题。 您需要做的就是创建一个新变量,其值由$ .support.Opacity属性确定,然后在代码的淡入/淡出部分中引用该变量。

$(function() {

var newHash      = "",
    $mainContent = $("#main-content"),
    $pageWrap    = $("#page-wrap"),
    baseHeight   = 0,
    $el,
    // new fadeTime property.
    fadeTime = $.support.opacity ? 500 : 0;



$("nav#footer").delegate("a", "click", function() {
    window.location.hash = $(this).attr("href");
    return false;
});

$(window).bind('hashchange', function(){

    newHash = window.location.hash.substring(1);

    if (newHash) {
        $mainContent
            .find("#guts")
            .fadeOut(fadeTime, function() {
                $mainContent.show().load(newHash + " #guts", function() {
                    $mainContent.fadeIn(fadeTime, function() {
                    });
                    $("nav#footer a").removeClass("current");
                    $("nav#footer a[href="+newHash+"]").addClass("current");
                });
            });
    };

});

$(window).trigger('hashchange');

});

如果用户不使用Internet Explorer,您只想运行某些内容?

尝试这个:

if ($.browser.msie) {
    return false;
} else {
    //do something
}

我假设您是在说对CSS opacity属性的支持,而不是对IE8及以下版本使用的-ms-filterfilter 在这种情况下,最好的方法是测试元素的style对象中属性的存在:

if('opacity' in document.createElement('div').style) {
    // Do something that requires native opacity support
}

(如果要测试多个属性,则可能要在其中缓存测试元素)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM