简单的jQuery回调在IE中断 [英] Simple jQuery callbacks break in IE
问题描述
我有几个这样的功能:
$(this).find('.subnav').fadeIn(200, buttonHide );
现在, buttonHide ,在这种情况下,在其他地方宣布。一旦200ms fadeIn完成,我想调用该函数。
Now, buttonHide, in this case, is a function I've declared elsewhere. Once the 200ms fadeIn is complete, I want to call that function.
很好。在FF和Safari中工作。但在IE中,它返回一个错误为undefined。事实上,我在Ariel Flesler的 scrollTo 中使用onAfter函数体验了SAME问题。
Great. Works in FF and Safari. In IE, though, it returns an error as undefined. In fact, I experienced the SAME problem using the onAfter function in Ariel Flesler's scrollTo... what gives?
我需要做什么为IE能够运行这些回调吗?
What do I have to do for IE to be able to run these callbacks?
编辑:这里是包含该函数的代码。这个页面被称为之后的片段...我有点noob;是一个问题?
here's the code that includes the function. This page is called AFTER the snippet above... I'm a bit of a noob; is that a problem? Nothing get's run until AFTER everything is loaded anyway.
jQuery(function( $ ){
/* BEGIN MENU SCROLLER INITIALIZATION */
// Resets pane
$('.menuClip').scrollTo( 0 );
// scrolls to active item to
$('body:not(.archive) .menuClip').stop().scrollTo( $('.current_page_item') );
$('.menuDown').click(function(){
$('.menuClip').stop().scrollTo( '+=70px', 800, {
onAfter:function(){
buttonHide();
},
});
});
$('.menuUp').click(function(){
$('.menuClip').stop().scrollTo( '-=70px', 800, {
onAfter:function(){
buttonHide();
},
});
});
/* END MENU SCROLLER INITIALIZATION */
});
$(buttonHide = function() {
setTimeout(function(){
var elemM = $(document).find('.menuClip:visible');
if (elemM[0].scrollHeight - elemM.scrollTop() == elemM.outerHeight()) {
$('.menuDown').animate({"opacity":"0"}, 200);
} else {
$('.menuDown').animate({"opacity":"1"}, 200);
}
if (elemM.scrollTop() == 0) {
$('.menuUp').animate({"opacity":"0"}, 200);
} else {
$('.menuUp').animate({"opacity":"1"}, 200);
}
}, 200);
});
推荐答案
我注意到一个问题: IE:
One thing I noticed: comma after a call back breaks IE:
$('#move_this_up').click(function(){
$('#content').stop().scrollTo( '-=270', 1000,
{ onAfter:function(){
inactiveContentStates();
}, // COMMA BAD!!!!
});
});
在调用函数之前声明函数并杀死逗号。
Declaring functions before calling them and killing the commas helped.
希望这对其他人有用!
这篇关于简单的jQuery回调在IE中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!