CSGO
V2EX  ›  问与答

初学习 HTML 和 CSS,求问 CSS 已经实现鼠标移上去有阴影动画,如何加上鼠标移出也有动画?

  •  
  •   CSGO · Aug 9, 2018 · 2825 views
    This topic created in 2859 days ago, the information mentioned may be changed or developed.
    12 replies    2018-08-09 11:01:35 +08:00
    InternetExplorer
        1
    InternetExplorer  
       Aug 9, 2018
    不要用动画,用“过渡”就好了。
    rabbbit
        2
    rabbbit  
       Aug 9, 2018   ❤️ 1
    <div></div>
    <style>
    div {width: 200px;height: 150px;border: 1px solid black;transition: 1s;}
    div:hover {box-shadow: 0 0 20px 0px rgba(0,0,0,1)}
    </style>
    wxsm
        3
    wxsm  
       Aug 9, 2018
    你这种应该用 transition,而不是 animation
    rabbbit
        4
    rabbbit  
       Aug 9, 2018   ❤️ 1
    CSGO
        5
    CSGO  
    OP
       Aug 9, 2018
    @rabbbit 那如果我要初始值,是不是把初始值放入上面那个样式里就行。比如: box-shadow: 0 0 0 0 rgba(0,0,0,0);
    v2xiaolang
        6
    v2xiaolang  
       Aug 9, 2018
    学了多久到这了
    CSGO
        7
    CSGO  
    OP
       Aug 9, 2018
    @v2xiaolang 2 天了
    whitegerry
        8
    whitegerry  
       Aug 9, 2018
    css3 动画选择 position、scale、rotation、opacity。

    .banner {
    position: relative;
    flex: 1;
    height: 350px;
    background: rgba(0, 144, 255, 0.10);
    margin: 18px 10px;
    box-sizing: border-box;
    border-radius: 10px;
    }

    .banner::after {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    content: '';
    border-radius: 10px;
    box-shadow: 0 8px 55px rgba(0, 0, 0, .12);
    opacity: 0;
    transition: opacity .3s;
    }

    .banner:hover::after {
    opacity: 1;
    }
    chenno9
        9
    chenno9  
       Aug 9, 2018
    你给 banner 写一个相反的动画,
    @keyframes banner_animation1 {
    from {
    box-shadow: 0 8px 55px 0 rgba(0,0,0,0.12);
    }
    to {
    box-shadow: 0 0 0 0 rgba(0,0,0,0.00);
    }
    }
    #banner1,#banner2{
    animation: banner_animation1 1s forwards;
    }
    rabbbit
        10
    rabbbit  
       Aug 9, 2018
    CSGO
        11
    CSGO  
    OP
       Aug 9, 2018
    @rabbbit 嗯,谢谢,已经成功了。
    CSGO
        12
    CSGO  
    OP
       Aug 9, 2018
    @chenno9 谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2845 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 07:48 · PVG 15:48 · LAX 00:48 · JFK 03:48
    ♥ Do have faith in what you're doing.