2010-07-15 81 views
0

同樣,我正在使用來自我的前任的代碼,並且對此感到不知所措。它似乎是一個採樣導航腳本。它在IE中收到一條錯誤消息,說明Object doesn't support this property or method。以下是我縮小了錯誤的範圍。Javascript:IE錯誤,Firebug沒有犯錯誤。它在哪裏?

功能:

/** 
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+ 
* <http://cherne.net/brian/resources/jquery.hoverIntent.html> 
* 
* @param f onMouseOver function || An object with configuration options 
* @param g onMouseOut function || Nothing (use configuration options object) 
* @author Brian Cherne <[email protected]> 
*/ 
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0}; 
cfg=$.extend(cfg,g?{over:f,out:g}:f); 
var cX,cY,pX,pY; 
var track=function(ev){cX=ev.pageX; 
cY=ev.pageY; 
}; 
var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t); 
if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track); 
ob.hoverIntent_s=1; 
return cfg.over.apply(ob,[ev]); 
}else{pX=cX; 
pY=cY; 
ob.hoverIntent_t=setTimeout(function(){compare(ev,ob); 
},cfg.interval); 
}}; 
var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t); 
ob.hoverIntent_s=0; 
return cfg.out.apply(ob,[ev]); 
}; 
var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget; 
while(p&&p!=this){try{p=p.parentNode; 
}catch(e){p=this; 
}}if(p==this){return false; 
}var ev=jQuery.extend({},e); 
var ob=this; 
if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t); 
}if(e.type=="mouseover"){pX=ev.pageX; 
pY=ev.pageY; 
$(ob).bind("mousemove",track); 
if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob); 
},cfg.interval); 
}}else{$(ob).unbind("mousemove",track); 
if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob); 
},cfg.timeout); 
}}}; 
return this.mouseover(handleHover).mouseout(handleHover); 
}; 
})(jQuery); 

的的document.ready觸發線的錯誤:

var config = {  
     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)  
     interval: 50, // number = milliseconds for onMouseOver polling interval  
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)  
     timeout: 200, // number = milliseconds delay before onMouseOut  
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)  
    }; 

    $("ul#topnav li .sub").css({'opacity':'0'}); 
    $("ul#topnav li").hoverIntent(config); 

我在一個不知如何解決這一點,並最終獲得這部分固定。

在document.ready中定義的兩個函數。

function megaHoverOver(){ 
     $(this).find(".sub").stop().fadeTo('fast', 1).show(); 

     //Calculate width of all ul's 
     (function($) { 
      jQuery.fn.calcSubWidth = function() { 
       rowWidth = 0; 
       //Calculate row 
       $(this).find("ul").each(function() {      
        rowWidth += $(this).width(); 
       }); 
      }; 
     })(jQuery); 

     if ($(this).find(".row").length > 0) { //If row exists... 
      var biggestRow = 0; 
      //Calculate each row 
      $(this).find(".row").each(function() {        
       $(this).calcSubWidth(); 
       //Find biggest row 
       if(rowWidth > biggestRow) { 
        biggestRow = rowWidth; 
       } 
      }); 
      //Set width 
      $(this).find(".sub").css({'width' :biggestRow}); 
      $(this).find(".row:last").css({'margin':'0'}); 

     } else { //If row does not exist... 

      $(this).calcSubWidth(); 
      //Set Width 
      $(this).find(".sub").css({'width' : rowWidth}); 

     } 
    } 

    function megaHoverOut(){ 
     $(this).find(".sub").stop().fadeTo('fast', 0, function() { 
      $(this).hide(); 
     }); 
    } 

回答

0

以前:

The problem is almost certainly opacity , which is not supported in IE. Check out this nice quirksmode article on cross-browser opacity issues.

更正:作爲@patrick正確地指出,並備份與源代碼參考引導,jQuery是足夠聰明,用IE自身的特殊品牌的自動處理不透明度處理。無論OP的問題是什麼,這都不是答案。

+2

我看到的唯一'不透明'是在jQuery調用中,它被支持。 http://github.com/jquery/jquery/blob/master/src/css.js#L51 – user113716 2010-07-15 19:43:23

+0

@patrick - 即使他傳入地圖,jQuery是否清除它,而不是.css('x', 'Y')?如果是這樣,那我就糾正了。我真的應該走出去,更多地使用IE。 – 2010-07-15 19:57:39

+0

是的,jQuery接受一個地圖只是爲了設置多個屬性。一切都平等。儘管我不想說任何會迫使你使用IE * more *的東西。 ; o) – user113716 2010-07-15 20:40:57

0

我能夠無誤地運行該代碼(請參閱http://jsfiddle.net/veHEY/)。看起來問題可能出現在您通過配置對象傳入的megaHoverOvermegaHoverOut函數中。你有這些功能的代碼?

+0

BDukes,我會在一個編輯中發佈功能,所以它不是很混亂,它實際上會適合。 – Slevin 2010-07-15 19:57:24

+0

此外,這裏是這個引用的URL: http://www.ci.fayetteville.nc.us/files.aspx?do=showfolder&id=21&folder=Agendas – Slevin 2010-07-15 20:07:52

+0

Firebug現在返回此錯誤: $(「ul #topnav李「)。hoverIntent不是一個函數 – Slevin 2010-07-15 20:17:09