2011-02-12 62 views
1

我需要阻止IE识别插件中的淡入/淡出效果。我如何添加一行jQuery的功能检测代码这样: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) 

一些代码,我会在哪里添加此代码?有人能帮助我实现这个目标吗?请!

+0

老实说。我需要做的就是将support.opacity代码添加到它上面的插件中。有人与jQuery知识请帮助我:( – iamwhitebox 2011-02-12 05:28:00

回答

1

无法弄清楚为什么有人不编辑代码并回答问题。 您需要做的只是创建一个新的变量,其值由$ .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'); 

}); 
0

你只是想运行一些东西,如果用户不使用Internet Explorer?

试试这个:

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

`$ .browser.msie`可能不可靠,请考虑使用功能检测。请参阅文档http://api.jquery.com/jQuery.browser/ – limc 2011-02-12 02:38:16

+0

不,我知道我需要使用功能检测,但我怎么才能将我粘贴在顶部的代码行添加到我的插件?????? – iamwhitebox 2011-02-12 03:20:31

-1

我相信你说的支持,为CSS opacity财产,而不是轻微越野车-ms-filterfilter其中IE8及以下使用。在这种情况下,最好的方法是在元素的style对象,以测试属性是否存在:

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

(您可能想,如果你想测试多种性能有缓存测试元件)