tags:

views:

67

answers:

2

Hi,

I have written the following jquery sitting in the head tags of my HTML

It is supposed to bring the image that is being hovered over to full opacity and slide another image over it from the right, then return when un-hovered.

    <script type="text/javascript">
 $(function() {
  $('ul#img-nav li').css({
   "opacity": .5
  });

  $('ul#img-nav li').hover(function() {
   $(this).stop(true).animate({"opacity":1});
   $(this).children('.overlay').stop(true).animate({"left" : "18px" });


  }, function() {
   $(this).stop(true).animate({"opacity":.5});
   $(this).children('.overlay').stop(true).animate({"left" : "180px" });

  });
 });

</script>

This works fine in Safari, Chrome, IE (7,8) but not in FF 3.6.

Any suggestions why this might be?

Sorry I forgot to say that the opacity works but the sliding image doesn't.

Many thanks

UPDATE: new to stackoverflow so I hope i'm putting this requested code in the correct place

HTML:

<ul id="img-nav">
            <a href="index.html">
                <li>
                    <img src="images/nav-img1.jpg" alt="nav-img1" width="146" height="145" />
                    <img class="overlay" src="images/overlay-exterior.png" alt="overlay-exterior" width="123" height="135" />
                </li>
            </a>
            <a href="exterior.html">
                <li>
                    <img src="images/nav-img2.jpg" alt="nav-img2" width="146" height="145" />
                    <img class="overlay" src="images/overlay-exterior.png" alt="overlay-exterior" width="123" height="134" />
                </li>
            <a href="maintenance.html">
                <li>
                    <img src="images/nav-img3.jpg" alt="nav-img3" width="146" height="145" />
                    <img class="overlay" src="images/overlay-exterior.png" alt="overlay-exterior" width="123" height="134" />
                </li>
            <a href="other.html">
                <li class="last">
                    <img src="images/nav-img4.jpg" alt="nav-img4" width="146" height="145" />
                    <img class="overlay" src="images/overlay-exterior.png" alt="overlay-exterior" width="123" height="134" />
                </li>
            </a>        

    </ul><!--END #img-nav-->

CSS

ul#img-nav li   {float:left; width: 146px; margin-right:103px; position: relative; display:block; height: 145px; overflow:hidden;} 

ul#img-nav li img   {position:absolute; top:0; left:0;}

ul#img-nav li img.overlay   {position: absolute; top: 5px; left: 180px; }

I also want them to be clickable links.

Also, I have noticed the slider works in IE8 but not the opacity change.

NB. It works in IE6 too

Thanks again

UPDATE:

When testing using FF on a separate windows machine running XP (my main machine is Mac OSX 10.5) it still doesn't slide across, just the opacity changes (which is the original problem).

+1  A: 

Ok, seems your HTML is not valid. a tags should not wrap li ones, see HTML below. With that change the JS also needed to change.

As a side note, instead of the chained children().children(..) calls a single find(..) call will also work.

<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"&gt;&lt;/script&gt;
<script type="text/javascript">

    $(function() {
        $('ul#img-nav li').css({
            "opacity": .5
        });

        $('ul#img-nav li').hover(function() {
            $(this).stop(true).animate({"opacity":1});
            $(this).children().children('.overlay').stop(true).animate({"left" : "18px" });
        }, function() {
            $(this).stop(true).animate({"opacity":.5});
            $(this).children().children('.overlay').stop(true).animate({"left" : "180px" });
        });

    });
</script>
<style type="text/css"> 
    ul#img-nav li   {float:left; width: 146px; margin-right:103px; position: relative; display:block; height: 145px; overflow:hidden;} 
    ul#img-nav li img   {position:absolute; top:0; left:0;}
    ul#img-nav li img.overlay   {position: absolute; top: 5px; left: 180px; }
</style>
</head>
<body>

<ul id="img-nav">
    <li>
        <a href="index.html">
            <img src="base.jpg" alt="nav-img1" width="146" height="145" />
            <img class="overlay" src="overlay.png" alt="overlay-exterior" width="123" height="135" />
        </a>
    </li>
    <li>
        <a href="exterior.html">
            <img src="base.jpg" alt="nav-img2" width="146" height="145" />
            <img class="overlay" src="overlay.png" alt="overlay-exterior" width="123" height="134" />
        </a>
    </li>
    <li>
        <a href="maintenance.html">
            <img src="base.jpg" alt="nav-img3" width="146" height="145" />
            <img class="overlay" src="overlay.png" alt="overlay-exterior" width="123" height="134" />
        </a>
    </li>
    <li class="last">
        <a href="other.html">
            <img src="base.jpg" alt="nav-img4" width="146" height="145" />
            <img class="overlay" src="overlay.png" alt="overlay-exterior" width="123" height="134" />
        </a>
    </li>
</ul>

</body>
</html>
Jonathan
Made some modifications.
Jonathan
Thats got it thanks very much
alan
A: 

Works fine on FF for me. Perhaps you cannot load the icon, making it appear as if nothing is happening on Firefox?

http://jsfiddle.net/NGyxN/2/

Peeter
the .png i'm trying to slide across loads fine when I browse for it in Firebug. Is that what you mean? Cheers
alan
Did the jsfiddle link work for you?
Peeter