【问题标题】:mouse hover in CSS3CSS3中的鼠标悬停
【发布时间】:2012-11-19 09:30:18
【问题描述】:

有这个 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 的解决方案...谢谢!

【问题讨论】:

  • 嗨,我的演示工作(尝试将鼠标放在数字上)现在可以工作了吗?
  • 不工作,我认为你做了广泛的区域,使位置可以在 jsfiddle 中使用
  • 请试试这个,它最有效...jsfiddle.net/FLe4g/9
  • jsfiddle.net/oceog/FLe4g/10 我只能得到这个
  • 非常感谢!它有效!

标签: css animation hover css-transitions


【解决方案1】:

对于后退动画,我使用了过渡,所以当你前进时使用动画帧,当你后退时使用过渡:

#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; 
    }​

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-12
    • 2011-08-04
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 2015-04-22
    • 2011-05-26
    • 2017-10-14
    相关资源
    最近更新 更多