Hover state is maintained during a transition even if the element has gone

前端 未结 6 2094
有刺的猬
有刺的猬 2021-02-20 01:52

Consider a simple element, and its associated CSS:

Hover me !


        
6条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 02:21

    Check if this is the behaviour you want to accomplish. Some are example styles, adjust as you please.

    http://jsfiddle.net/U44Zf/9/

    .tooltip {
        background-color: white;
        border: 1px solid black;
        padding: 10px;
        opacity: 0;
        transition: 1s 500ms;
        transition-property: transform, opacity;
        position: absolute;
        right: 0;
        top: 0;
    }
    
    #content:hover .tooltip {
        display: block;
        opacity: 1;
        transform:translateX(100px);
        -webkit-transform: translateX(100px);
    }
    #content {
        transition: 1s 500ms;
        transition-property: background-color, color;
        cursor: pointer;
        position: relative;
    }
    #content.active {
        background-color: blue;
        color: white;
    }
    #content.active .tooltip {
        opacity: 0;
        transform: none;
        -webkit-transform: none;
    }
    

    I've added this javascript snippet to control the click state

    $('#content').click(function () {
        $(this).toggleClass('active');
    });
    

提交回复
热议问题