tags:

views:

92

answers:

3

Hello,

I've seen examples for load() and ready(), but they always seem to apply to the window or document body, or a div or img or something like that.

I have a hover() function, and when you hover over it, it uses fadeIn() to reveal it. Problem is, the images inside the div aren't loaded yet, so it ends up just appearing anyway. I need code that will only allow the image to fade when it's contents are fully loaded. When I just plug in other selectors like the following, it doesn't work

$(this).next(".menuPopup").ready(function () { //or load(), neither work
  fadeTo(300, 1);
});

EDIT: Relevant code

     $( '.leftMenuProductButton' ).hover (
            function () {

                                $(this).next(".menuPopup").stop().css("opacity", 1).fadeIn('slow');


            },
            function () {



                $(this).next(".menuPopup").stop().hide();


    });

HTML

<div class="leftMenuProductButton"> Product 1</div>
                                <div id="raceramps56" class="menuPopup"><IMG SRC="myimage.jpeg"> </div>
A: 

The function

$(window).load()

is probably what you're looking for.

See: SO post

Tom Tresansky
Yes, but I have multiple popups that this occurs with. window load() doesn't work after the initial page has loaded, and changes are being made.
Jared
A: 

You could use window.onLoad, that doesn't fire until everything is loaded.

kekekela
+3  A: 

You should probably go with chaining the animations:

$(this).next(".menuPopup").fadeIn(300, function() {
    $(this).children('.inside_image').css(
        'opacity':'0',
        'display':'show'
    );
    $(this).children('.inside_image').animate({
        opacity: '1'
    }, 300);
});

I've done something like this before, and it worked pretty well. I think a lot of Lightboxes do this.

dclowd9901
yeah that would work. Kudos!
Jared
Make sure you update the status of the question if an answer works out for you :)
dclowd9901
I was hoping someone would offer a solution oriented around load() or ready()
Jared
There's a time and place for every function. In my experience, this isn't the kind of script that best utilizes the load() or ready() functionality.
dclowd9901