JQuery show/hide when hover

后端 未结 5 512
名媛妹妹
名媛妹妹 2020-12-05 13:14

I have three links, Cat, Dog, Snakes. When I hover over each, the content relating to each link should change.

So if i hover over cat, then cat content will appear,

5条回答
  •  情深已故
    2020-12-05 13:57

    Since you're using jQuery, you just need to attach to some specific events and some pre defined animations:

    $('#cat').hover(function()
    {
         // Mouse Over Callback
    }, function()
    { 
         // Mouse Leave callback
    });
    

    Then, to do the animation, you simply need to call the fadeOut / fadeIn animations:

    $('#dog').fadeOut(750 /* Animation Time */, function()
    {
        // animation complete callback
         $('#cat').fadeIn(750);
    });
    

    Combining the two together, you would simply insert the animations in the hover callbacks (something like so, use this as a reference point):

    $('#cat').hover(function()
    {
         if($('#dog').is(':visible'))
            $('#dog').fadeOut(750 /* Animation Time */, function()
         {
            // animation complete callback
             $('#cat').fadeIn(750);
         });
    }, function()
    { 
         // Mouse Leave callback
    });
    

提交回复
热议问题