为什么执行两次?
我有这样的代码:为什么执行两次?
$(document).ready(function() {
$("div #covert, div #coverb").height($(window).height()/2 + 1);
$(window).resize(function() {
$("div #covert, div #coverb").height($(window).height()/2 + 1);
covconcr();
});
function covconcr() {
$('div #covercon').css('left', $(window).width()/2 - $('#covercon').width()/2);
}
covconcr();
function hidecover() {
var goup = $('div #covert').height();
}
$("div #covercon").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").delay(100).fadeIn("fast", function() {
$(this).stop();
});
$('title').html('Drink86_browser.detection');
var logoop;
jQuery.each(jQuery.browser, function() {
if ($.browser.msie) {
$('div #covercon').delay(3000, function() {
$(this).html("YOUR BROWSER IS: INTERNET EXPLORER.");
$('title').html('Drink86_your.browser.is.internet.explorer');
});
}
else if (!$.browser.msie) {
function update() {
//$('#site').load('site.php');
$('div #covercon').html("YOUR BROWSER IS: " + jQuery.uaMatch(navigator.userAgent).browser + ".");
covconcr();
$('title').html('Drink86_your.browser.is.' + jQuery.uaMatch(navigator.userAgent).browser + ' ');
function hidecov() {
$('title').html('Drink86_loading_files');
$('#covercon').html($('#loading').html());
covconcr();
var timer = setInterval(function() {
$("#loadingpro").html(Math.round($("#progress").width()/4) + "%");
}, 20);
$("#progress").animate({
width: 400
}, 2000, function() {
$('title').html('Drink86_');
clearInterval(timer);
$('#covercon').delay(700).fadeOut('fast', function() {
// if(logoop!="yes"){
$('#logobig').css('left', $(window).width()/2 - $('#logobig').width()/2).css('top', $(window).height()/2 - $('#logobig').height()/2);
$('#logobig').fadeIn(3000).delay(2500).fadeOut(3000);
logoop = "yes";
// }
});
});
}
setTimeout(hidecov, 1000);
}
setTimeout(update, 3100);
}
});
});
与#logobig
(fadeIn
和fadeOut
)操作被执行两次。 为什么? 我之前遇到过类似于Firefox的问题,但之后他们只是在Firefox中执行了两次。 有什么想法为什么?
究竟是你与
jQuery.each(jQuery.browser, function() { ...
这确实是没有意义的思考。只要看看jQuery.browser
(如果你必须的话)。
此外,检查,看它是否在IE的“如果”语句,然后如果它不是IE浏览器中的“其他”的一部分,那么,再次...
直接回答你的问题是, jQuery.browser
可能有两件事,所以你做了两次。
我认为你的问题是,你正在迭代jQuery的浏览器标志集合,这不是完成你正在做的事情所必需的。如果您在Firefox中查看页面,则if/elseif的第二个子句将在每个循环中执行,因为值永远不会更改。尝试从每个环路去除功能,因此,它只是看起来像这样:
if ($.browser.msie) {
$('div #covercon').delay(3000, function() {
$(this).html("YOUR BROWSER IS: INTERNET EXPLORER.");
$('title').html('Drink86_your.browser.is.internet.explorer');
});
} else if (!$.browser.msie) {
function update() {
//$('#site').load('site.php');
$('div #covercon').html("YOUR BROWSER IS: " + jQuery.uaMatch(navigator.userAgent).browser + ".");
covconcr();
$('title').html('Drink86_your.browser.is.' + jQuery.uaMatch(navigator.userAgent).browser + ' ');
function hidecov() {
$('title').html('Drink86_loading_files');
$('#covercon').html($('#loading').html());
covconcr();
var timer = setInterval(function() {
$("#loadingpro").html(Math.round($("#progress").width()/4) + "%");
}, 20);
$("#progress").animate({
width: 400
}, 2000, function() {
$('title').html('Drink86_');
clearInterval(timer);
$('#covercon').delay(700).fadeOut('fast', function() {
// if(logoop!="yes"){
$('#logobig').css('left', $(window).width()/2 - $('#logobig').width()/2).css('top', $(window).height()/2 - $('#logobig').height()/2);
$('#logobig').fadeIn(3000).delay(2500).fadeOut(3000);
logoop = "yes";
// }
});
});
}
setTimeout(hidecov, 1000);
}
setTimeout(update, 3100);
}
我不是最好的使用Javascript,所以我可能是完全关上这一点,但它看起来像hidecov可以运行当更新被调用时,然后在1秒后再次通过。
在hidecov内部使用带有断点的萤火虫应指向何时开始运行。
你叫内update()
,然后setTimeOut(update, 3100)
外更新的,所以hidecov
将一次1000毫秒后调用,然后update
将在3100ms调用,并在那里将做另一setTimeout
上hidecov
在1000毫秒。
我不确定这段代码试图做什么,所以我不能告诉你如何改变它,但我可以看到为什么hidecov
被调用两次。
jQuery.each(jQuery.browser
做的每个项目,不是循环的“浏览器”的对象。我怀疑有超过一个的!$。browser.msie
因为JavaScript一个残酷的主人 – bobobobo 2010-10-20 23:02:04
在行格式之前有4个空格作为代码,'ctr-k'代表选择 – 2010-10-20 23:06:23
你试过用Firebug步进javascript吗? – drudge 2010-10-20 23:08:06