views:

873

answers:

2

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!

+2  A: 
$("#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.

Alexander Gyoshev
Mighty, thanks!
Nimbuz
+1  A: 

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();
});
Eric
Almost the same as Alexander, but he posted earlier. Thanks anyway Eric, much appreciated :-)
Nimbuz