簡體   English   中英

CSS3中的鼠標懸停

[英]mouse hover in CSS3

擁有以下CSS3代碼:

#box1
    {
    position: relative;
    width: 300px;
    border: 1px solid black;
    box-shadow:  -3px 8px 34px  #808080;
    border-radius: 20px;
    box-shadow: -8px 5px 5px #888888;
    right: 700px; 
    top:  -200px;
    height:  150px;
}


@-webkit-keyframes myfirst {
    0%   { right:700px; top:-200px;background: yellow;}
    50%  {background:blue; right:700px; top:200px;}
    100% { right:700px; top:-200px; background: yellow}
}

#stam {
    font-size: large;
    background: green;
    width: 100px;
    top: 400px;
    position: absolute;
}

#stam:hover ~ #box1 { -webkit-animation:myfirst 2s; }

您可以在此處查看代碼的工作原理: http//jsfiddle.net/FLe4g/2/

我的問題是:如何制作動畫,所以當我將鼠標放在“ stam” div上時,動畫將停止在動畫的“ 50%” ( 50% {background:blue; right:700px; top:200px;})上動畫,只有當我將鼠標從“ stam” div移開時,動畫才繼續嗎? 我真的更喜歡該解決方案將使用CSS3而不是js ...謝謝!

對於后向動畫,我使用了過渡,所以當您向前移動時,您會使用動畫幀;而當您向后移動時,您會使用過渡:

#box1
    {
    position: relative;
    width: 300px;
    border: 1px solid black;
    box-shadow:  -3px 8px 34px  #808080;
    border-radius: 20px;
    box-shadow: -8px 5px 5px #888888;
    right: 300px; 
    top:  -200px;
    height:  150px;
    -webkit-transition: all 2s;
}


@-webkit-keyframes myfirst {
    0%   { right:300px; top:-200px;background: yellow;}
    100%  {background:blue; right:500px; top:200px;}
}

#stam {
    font-size: large;
    background: green;
    width: 100px;
    top: 400px;
    position: absolute;
}

#stam:hover ~ #box1 { 
    -webkit-transition: all 0s;
    background:blue; right:500px; top:200px;
    -webkit-animation:myfirst 2s; 
    -webkit-animation-fill-mode: forwards; 
    }​

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM