views:

57

answers:

1

I put together a fading menu of sorts if you want to call it that. The problem that I am having is everything fades fine except the image I am appending to the end of the links. It fades out great, but I cannot get fadeIn to work at all.

Preview: http://cu3ed.com/jqfade/

$(document).ready(function() {

$(".fade").hover(
    function () {
        $(this).fadeIn(500).append($("IMAGE HERE"));
        $(this).stop().animate({
            opacity: 1,
            borderBottomColor: "#6BD8FF",
            borderLeftColor: "#6BD8FF",
            borderRightColor: "#6BD8FF",
            borderTopColor: "#6BD8FF",
            color: "#03A5DF",
            backgroundColor: "#E3F8FF"
        }, 500);
    },
    function () {
        $(this).find("img:last").fadeOut(200);
        $(this).stop().animate({
            opacity: 1,
            borderBottomColor: "#CCCCCC",
            borderLeftColor: "#CCCCCC",
            borderRightColor: "#CCCCCC",
            borderTopColor: "#CCCCCC",
            color: "#BBBBBB",
            backgroundColor: "#F9F9F9"
        }, 200);
    }
);

});

Changing the fadeIn time does nothing and if you look at it a bit you can tell it's not fading in but just appearing. Everything else is working fine. If anyone has some assistance I would really appreciate it. Thanks!

+1  A: 

edit: original below for historic reasons

I've got this problem solved, you can find the solution at http://jsbin.com/hogantest/5 and of course see all the source and play with it at http://jsbin.com/hogantest/5/edit

Because stop() does not work with fadeIn() and fadeOut() there is a funkyness with the arrows sticking around if you move the mouse pointer fast. I leave the fix for the OP.

Here were the issues and solution. Problem 1 was not using stop correctly. You only want to use stop on the fade out item. This will stop the fade in and start a fade out right away. Also (as my original comment) you want to stop first then do the work.

Problem 2 was the dynamic adding of images in the hover. YIKES! Add the images in hidden once and only once, then manipulate them.

Here is the relevant part of the revised code:

$(document).ready(function() {
  $(".fade").each( function() {
    $(this).append($("<img style='float:right;' src='http://cu3ed.com/jqfade/img/plus.png' />"));
    $(this).find("img:last").hide();
  });

  $(".fade").hover(
    function () {
      var me = $(this);

      me.find("img:last").fadeIn(500);

      me.animate({
        opacity: 1,
        borderBottomColor: "#6BD8FF",
        borderLeftColor: "#6BD8FF",
        borderRightColor: "#6BD8FF",
        borderTopColor: "#6BD8FF",
        color: "#03A5DF",
        backgroundColor: "#E3F8FF"
      }, 500);
    },
    function () {
      var me = $(this);
      me.stop();
      me.find("img:last").fadeOut(200);
      me.animate({
        opacity: 1,
        borderBottomColor: "#CCCCCC",
        borderLeftColor: "#CCCCCC",
        borderRightColor: "#CCCCCC",
        borderTopColor: "#CCCCCC",
        color: "#BBBBBB",
        backgroundColor: "#F9F9F9"
      }, 200);
    }
  );

});​

As I said there is still a fix -- get rid of fadeIn() and fadeOut() and use animate so you can call stop(). I would also add the img tag to the original html code, there is no reason to add it dynamically unless this is a grease monkey script or something of that sort.

original answer

This is a guess, it is late so I'm not testing it... move the stop() before the image fade in.

function () {
       var me = $(this);
       me.stop();
       me.fadeIn(500).append($("<img class='plus' src='img/plus.png' />"));
       me.animate({
            opacity: 1,
            borderBottomColor: "#6BD8FF",
            borderLeftColor: "#6BD8FF",
            borderRightColor: "#6BD8FF",
            borderTopColor: "#6BD8FF",
            color: "#03A5DF",
            backgroundColor: "#E3F8FF"
        }, 500);
    },
Hogan
Thanks for the reply.I tried changing the code and it still doesn't reflect a fade in. So, still not working. If you get a chance later on to test, that would be awesome. Thanks again.
Ce.
Wow thanks so much for the thorough response! Much appreciated. I'm going to read through it a few more times to try and grasp it all. Thank you!
Ce.