CSS Transition on Hover

后端 未结 6 686
再見小時候
再見小時候 2021-01-28 13:50

I have a problem. I actually try to do a transition at a div when I hover the mouse over an object. So basically I have a div, and when I hover my mouse the div, it should displ

6条回答
  •  星月不相逢
    2021-01-28 14:33

    By smoother do you mean fade in? Here is an example of fading in on #on-hover. I use pointer-events:none to ignore hover on and pass the event on to its parent #on-hover.

    jsFiddle

    #first,
    #on-hover {
        width:100px;
        height:100px;
    }
    
    #first {
        background-color:#F00;
    }
    
    #on-hover {
        opacity:0;
        background-color:#0F0;
        -webkit-transition:opacity .5s ease;
        -moz-transition:opacity .5s ease;
        transition:opacity .5s ease;
    }
    
    #on-hover:hover {
        opacity:1;
    }
    
    #on-hover img {
        pointer-events:none;
    }
    

提交回复
热议问题