0

This looks really bloated, can it be rewritten any better/more compact:

$("#cart-summary").hover(
      function () {
        $('.flycart').slideDown('fast');
      }
   );
   $(".flycart").hover(
      function () {}, // mousein function not required
      function () { // hide menu on mouseout
        $('.flycart').slideUp('fast');
      }
   );
    $('.flycart a.close').click(function(){
        $(this).parents('.flycart').hide();
    });

Thanks!

1
  • Nope, compared to the accepted answer. :-) Commented Oct 1, 2009 at 14:53

2 Answers 2

2
$("#cart-summary").mouseenter(function () {
    $('.flycart').slideDown('fast');
});

$(".flycart")
    .mouseleave(function () {
        $(this).slideUp('fast');
    })
    .find('a.close')
        .click(function(){
            $(this).parents('.flycart').hide();
        });

It's a small improvement, though. I couldn't guess the relationship between the #cart-summary and the .flycarts.

Sign up to request clarification or add additional context in comments.

Comments

1

In short, no. However, you can do without the empty hover function: just use mouseenter() and mouseleave(). mouseover and mouseout have subtle differences to mouseenter and mouseleave. Look at the jQuery API for more info.

$("#cart-summary").mouseenter(function()
{
    $('.flycart').slideDown('fast');
});

$(".flycart").mouseleave(function()
{
    $(this).slideUp('fast');
});

$('.flycart a.close').click(function()
{
    $(this).parents('.flycart').hide();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.