views:

172

answers:

2

So my problem is rather simple and complex at the same time. I am trying to create links that fade in when you mouseover them and fade out when you mouseout of them. At the same time that you are going over them I would like a pic to slide from the left. This is the easy part, I have every thing working. The image fades and another image slides. I did this by using a hover, fadeto, and toggle("slide"). I would like to do this in a table format with multiple images being able to be scrolled over and sliding images out. The problem is that I am calling my sliding image to a class and when I hover over the letters both images slide out. Does anybody have a solution for this?

I posted the code that I used below:

<html>
<head>
<script type='text/javascript' src='http://accidentalwords.squarespace.com/storage/jquery/jquery-1.4.2.min.js'&gt;&lt;/script&gt;
<script type='text/javascript' src='http://accidentalwords.squarespace.com/storage/jquery/jquery-custom-181/jquery-ui-1.8.1.custom.min.js'&gt;&lt;/script&gt;

<style type="text/css">
    .text-slide { display: none; margin: 0px; width: 167px; height: 50px; }
</style>

<script>
$(document).ready(function(){
$(".letterbox-fade").fadeTo(1,0.25);
$(".letterbox-fade").hover(function () {
  $(this).stop().fadeTo(250,1);
  $(".text-slide").toggle("slide", {}, 1000);
  },
  function() {
    $(this).stop().fadeTo(250,0.25);
    $(".text-slide").toggle("slide", {}, 1000);
});
});

</script>
</head>

<body style="background-color: #181818">

<table>
<tr>
<td><div class="letterbox-fade"><img src="http://accidentalwords.squarespace.com/storage/sidebar/icons/A-Letterbox-Selected.png" /></div></td>
<td><div class="text-slide"><img src="http://accidentalwords.squarespace.com/storage/sidebar/icons/TEST.png" /></div></td>
</tr>
<tr>
<td><div class="letterbox-fade"><img src="http://accidentalwords.squarespace.com/storage/sidebar/icons/B-Letterbox-Selected.png" /></div></td>
<td><div class="text-slide"><img src="http://accidentalwords.squarespace.com/storage/sidebar/icons/TEST.png" /></div></td>
</tr>
</table>

</body>
</html>
A: 

You could change the scope of the selector, for example

$(this).parent().find(".text-slide").toggle("slide", {}, 1000); 

will limit jQuery's searching to the <td>

t_scho
I am confused how that would work? Does this replace the line: .closest("tr").find(".text-slide").toggle("slide", {}, 1000);Because I replaced it and the slide does not work anymore.
Slick Willis
A: 

You can change it around so it goes up to the <tr> then searches for the cousin .text-slide using .closest() and .find(), like this:

$(".letterbox-fade").hover(function () {
  $(this).stop().fadeTo(250,1)
         .closest("tr").find(".text-slide").toggle("slide", {}, 1000);
}, function() {
  $(this).stop().fadeTo(250,0.25)
         .closest("tr").find(".text-slide").toggle("slide", {}, 1000);
});
Nick Craver
That works perfectly!!! Thanks so much. The next question is what do I use to make it so that if the mouse leaves before the picture fully slides out it slides back instead of completing the motion?
Slick Willis
@SlideWillis - add a `.stop()` before that `.toggle()` :)
Nick Craver
Hmmm, that did not work. It just stops the slide from coming out all together. Doesn't a .stop finish the current event and wait until the next one is activated? I am looking for it to go onto the next even when the mouse leaves even if it doesn't finish the previous one.
Slick Willis
@Slick - You'll have some issues there because it doesn't know how far to slide it in, but you can do `.stop(true, true)` to jump the end of the queue.
Nick Craver
It worked, but like you said there are some issues. Mainly it stutters, before it goes in. Basically it flickers the whole word showing the end result then slides it in. Why is it getting lost with sliding it in, I am not giving a distance, just a duration? Would it be better to use a .animate?
Slick Willis
@Slick - an animate with specific left or width properties would make it completely smooth, of course the image has to be a known size for this to work, but then a `.stop().animate()` works.
Nick Craver