JQuery show/hide when hover

后端 未结 5 513
名媛妹妹
名媛妹妹 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:56

    I hope my script help you.

    <i class="mostrar-producto">mostrar...</i>
    <div class="producto" style="display:none;position: absolute;">Producto</div>
    

    My script

    <script>
    $(".mostrar-producto").mouseover(function(){
         $(".producto").fadeIn();
     });
    
     $(".mostrar-producto").mouseleave(function(){
          $(".producto").fadeOut();
      });
    </script>
    
    0 讨论(0)
  • 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
    });
    
    0 讨论(0)
  • 2020-12-05 13:58
    ('.cat').hover(
      function () {
        $(this).show();
      }, 
      function () {
        $(this).hide();
      }
    );
    

    It's the same for the others.

    For the smooth fade in you can use fadeIn and fadeOut

    0 讨论(0)
  • 2020-12-05 14:03

    This code also works.

    $(".circle").hover(function() {$(this).hide(200).show(200);});
    .circle{
        width:100px;
        height:100px;
        border-radius:50px;
        font-size:20px;
        color:black;
        line-height:100px;
        text-align:center;
        background:yellow
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
    <div class="circle">hover me</div>

    0 讨论(0)
  • 2020-12-05 14:09

    jquery:

    $('div.animalcontent').hide();
    $('div').hide();
    $('p.animal').bind('mouseover', function() {
        $('div.animalcontent').fadeOut();
        $('#'+$(this).attr('id')+'content').fadeIn();
    });  
    

    html:

    <p class='animal' id='dog'>dog url</p><div id='dogcontent' class='animalcontent'>Doggiecontent!</div>
    <p class='animal' id='cat'>cat url</p><div id='catcontent' class='animalcontent'>Pussiecontent!</div>
    <p class='animal' id='snake'>snake url</p><div id='snakecontent'class='animalcontent'>Snakecontent!</div>
    

    -edit-

    yeah sure, here you go -- JSFiddle

    0 讨论(0)
提交回复
热议问题