Hover over a hidden element to show it

后端 未结 6 1426
臣服心动
臣服心动 2020-12-14 17:19

Is there any way to hover over an element that\'s already hidden. I am trying to mimic what Steam does with their arrow navigation on their home page. You\'ll notice that wh

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 17:43

    You cannot hover over an invisible element or an undisplayed element. You can hover over a visible element and then use that to show a different previously hidden element. Or you can hover over a transparent element and make it opaque.

    Here is an example of the opacity technique using just CSS, it would also work with jQuery's hover.

    CSS:

    #it {
        opacity: 0;
        width: 500px;
        height:500px;
    }
    
    #it:hover {
        opacity: 1;
    }
    

    Here is an example of showing one element when another is hovered over:

    HTML:

    Hover over me to display something else
    Something else

    jQuery:

    $("#me").hover(function(){
       $("#else").show();
    },function(){
       $("#else").hide();
    });
    

提交回复
热议问题