Simple jQuery callbacks break in IE

左心房为你撑大大i 提交于 2019-12-10 20:14:50

问题


I have a few functions like this:

$(this).find('.subnav').fadeIn(200, buttonHide );

Now, buttonHide, in this case, is a function I've declared elsewhere. Once the 200ms fadeIn is complete, I want to call that function.

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?

What do I have to do for IE to be able to run these callbacks?

EDIT: 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);
});

回答1:


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.

Hope this is of use to others!



来源:https://stackoverflow.com/questions/2366410/simple-jquery-callbacks-break-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!