views:

15

answers:

2

Issue: When page runs in FF 3.6 the fadeIn doesn't show, until after you've cycled through the galleries, then it works. How can I fix this?

Jquery Code

    $(document).ready(function() {
      $("#gallerylinks a").each(function(index){
        $(this).click(function(){
          $(".gallerymain").hide();
          $("#gal"+index).fadeIn();
        });
      });
    });

HTML Code

<table width="960" border="0" cellspacing="0" cellpadding="0" id="gallerylinks">
      <tr>
        <td><a href="#"><img src="images/somename1.jpg" width="240" height="186" /></a></td>
        <td><a href="#"><img src="images/somename2.jpg" width="240" height="186" /></a></td>
        <td><a href="#"><img src="images/somename3.jpg" width="240" height="186" /></a></td>
        <td><a href="#"><img src="images/somename4.jpg" width="240" height="186" /></a></td>
      </tr>
    </table>
+3  A: 

The fade won't work correctly because the images aren't loaded the first round, instead of this:

$(document).ready(function() {

Do this:

$(window).load(function() {

The difference is that window.onload waits for images to be loaded, so they'll be there before the code runs...even the first time :)

Alternatively, you can pre-load the images when loading the gallery, there are many options out there for this.

Nick Craver
Brilliant! Thank you kindly.
vendy-dah-vindow-viper
@vendy-dah-vindow-viper - Welcome :) If an answer resolved your issue be sure to mark it as accepted via the check-mark on the left :)
Nick Craver
A: 

You should try this:

$(window).load(function(){
  $('#gallerylinks a').click(function(){
    $(".gallerymain").hide();
    $("#gal"+index).fadeIn('fast');
  });
});
Mitch C
There aren't any direct children like this, a `<table>` can't have any `<a>` children...so this wouldn't bind to any elements :)
Nick Craver
You're absolutely right. I updated the code and removed the ">" the child selector. There's no need in the additional performance hit for the loop in the source above.
Mitch C