views:

191

answers:

1

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  A: 

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!

Benjamin Allison