<script type="text/javascript">
$(document).ready(function() {
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();
});
}
var config = {
sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
interval: 100, // 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);//这两句报错说未将对象引用到设置对象的实例
});</script>
这个 JS控制我的一个下拉菜单,最后两句报错!请问下 最后那两句什么意思??我应该如何改正呢??谢谢拉!
$(document).ready(function() {
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();
});
}
var config = {
sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
interval: 100, // 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);//这两句报错说未将对象引用到设置对象的实例
});</script>
这个 JS控制我的一个下拉菜单,最后两句报错!请问下 最后那两句什么意思??我应该如何改正呢??谢谢拉!
<ul id="topnav">
<li>
</li>
</ul>
找不到对象
$("ul#topnav li").hoverIntent(config);//这两句报错说未将对象引用到设置对象的实例
楼主,意思就是说$("ul#topnav li .sub")和$("ul#topnav li")得到的值为null
你就没有名字叫topnav 的li
请楼主把页面body中的相关代码放出来
要不就自己在改改,看看要对哪一个ui下的li做上面的效果
<ul id="topnav">
<li>
<div class="menu"><a href="#">Home</a></div>
</li>
<li>
<div class="menu"><a href="#">Solutions</a></div>
<div class="sub" style=" left:-230px;">
<ul>
<li><h2><a href="#">Desktop</a></h2></li>
<li><a href="#">Navigation Link</a></li>
<li><a href="#">Navigation Link</a></li>
</ul>
</div>
</li>
</ul>
<li>
<div class="menu"><a href="#">Home</a></div>
</li>
<li>
<div class="menu"><a href="#">Solutions</a></div>
<div class="sub" style=" left:-230px;">
<ul>
<li><h2><a href="#">Desktop</a></h2></li>
<li><a href="#">Navigation Link</a></li>
<li><a href="#">Navigation Link</a></li>
</ul>
</div>
</li>
</ul>
谢谢答复