gpt4 book ai didi

javascript - CSS3 或 Javascript - 简单的填充动画

转载 作者:太空宇宙 更新时间:2023-11-03 20:51:12 24 4
gpt4 key购买 nike

我正在尝试创建一个简单的动画,当用户将鼠标悬停在某个元素上时,其中包含的另一个元素会填充其父元素。目前,我有一个 JSFiddle 可以做到这一点。

但是,我想用一些其他功能来完成这个,我不确定我是否可以在 CSS3 中真正做到。

  1. 我正在尝试找到一种方法,让内圆完全填充其父级(即当其宽度/高度 = 300 像素时),我希望填充在动画完成。

  2. 当用户将鼠标移出 :hover 范围时,我希望动画反转方向而不是突然停止。

我已经使用 CSS3 走了这么远,但我不确定我是否可以在不借助 Javascript 的情况下实现这两个功能。有谁知道完全在 CSS3 中执行此操作的方法/有谁知道是否可以在 CSS3 中执行最后两个功能,因为我似乎找不到任何东西。

.circle {
width: 300px;
height: 300px;
background-color: white;
border: 1px solid #000000;
overflow: hidden;

border-radius: 150px;
-moz-border-radius: 150px;
-webkit-border-radius: 150px;
}

.filler {
width: 0px;
height: 0px;
background-color: red;
border: none;
position: relative;
left: 50%;
top: 50%;

border-radius: 150px;
-mox-border-radius: 150px;
-webkit-border-radius: 150px;

animation: empty 1s;
}

.circle:hover .filler {
animation: fill 2s;
-moz-animation: fill 2s;
-webkit-animation: fill 2s;
background-color: blue;
}

@keyframes fill
{
from {background: red; height: 0px; width: 0px;}
to {background: green; height: 300px; width: 300px; top: 0%; left: 0%;}
}

@-moz-keyframes fill /* Firefox */
{
from {background: red; height: 0px; width: 0px;}
to {background: green; height: 300px; width: 300px; top: 0%; left: 0%;}
}

@-webkit-keyframes fill /* Safari and Chrome */
{
from {background: red; height:0px; width:0px;}
to {background: green; height: 300px; width: 300px; top: 0%; left: 0%;}
}

@keyframes empty
{
to {background: red; height: 0px; width: 0px; top: 50%; left: 50%;}
}
@-moz-keyframes empty
{
to {background: red; height: 0px; width: 0px; top: 50%; left: 50%;}
}
@-webkit-keyframes empty
{
to {background: red; height: 0px; width: 0px; top: 50%; left: 50%;}
}

JS Fiddle

最佳答案

这个简单的动画不需要关键帧。这是您需要的 CSS:

.circle {
position: relative;
width: 300px;
height: 300px;
background-color: white;
border: 1px solid #000000;
border-radius: 150px;
overflow: hidden;
}

.filter {
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
background-color: red;
border-radius: 0px;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
}

.circle:hover .filter {
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 150px;
background-color: blue;
}

和 HTML:

<div class="circle">
<div class="filter"></div>
</div>

这是一个例子:http://jsbin.com/agekef/1/edit

关于javascript - CSS3 或 Javascript - 简单的填充动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15826400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com