물 채우기 애니메이션
원 을 물로 채우는 것처럼 보이도록 닦기 애니메이션을 얻으려고합니다 . 두 가지 오류가 발생했으며 세 번째 오류도 해결하지 못했습니다.
- 잘못된 길을 채워
-
채워지면 빈 (검은 색)으로 재설정됩니다.* - 지금은
<img>
태그를 사용하고 있지만이 효과를로 옮기고 싶은데body { background-image: }
이를 수행하는 방법에 대한 지침이 필요합니다.
#banner {
width: 300px;
height: 300px;
position: relative;
}
#banner div {
position: absolute;
}
#banner div:nth-child(2) {
-webkit-animation: wipe 6s;
-webkit-animation-delay: 0s;
-webkit-animation-direction: up;
-webkit-mask-size: 300px 3000px;
-webkit-mask-position: 300px 300px;
-webkit-mask-image: -webkit-gradient(linear, left bottom, left top, color-stop(0.00, rgba(0, 0, 0, 1)), color-stop(0.25, rgba(0, 0, 0, 1)), color-stop(0.27, rgba(0, 0, 0, 0)), color-stop(0.80, rgba(0, 0, 0, 0)), color-stop(1.00, rgba(0, 0, 0, 0)));
}
@-webkit-keyframes wipe {
0% {
-webkit-mask-position: 0 0;
}
100% {
-webkit-mask-position: 300px 300px;
}
}
<div id="banner">
<div>
<img src="http://i.imgur.com/vklf6kK.png" />
</div>
<div>
<img src="http://i.imgur.com/uszeRpk.png" />
</div>
</div>
@anpsmn이 제안한 대로 기본 마스크 위치를 지정 하면 더 이상 검은 색으로 재설정되지 않습니다.
이는 단일 div 및 유사 요소 로 달성 할 수 있습니다 ::before
.
은
#banner
주어진border-radius: 50%
원을 만들고overflow: hidden
그 안에 아이를 클립하기::before
의사 요소 100 % 높이 애니메이션 및 애니메이션하여 100 % 일시 값 . 그것은 사용으로 바닥에서 시작됩니다.forwards
bottom: 0
배경 이미지가에 검은 색과 파란색 배경의 장소에 적용 할 것입니다
#banner
및#banner::before
호환성 : IE10 + 및 모든 최신 브라우저. -webkit-
앞에 둔 재산은 대부분 더 이상 필요 당신의 키 프레임 애니메이션입니다. caniuse.com에서 여기에있는 브라우저 호환성 차트를 확인하세요.
작업 예
cubic-bezier(.2,.6,.8,.4)
@ChrisSpittles 답변에 설명 된 내용 을 추가했습니다 . 깔끔한 효과를 제공합니다!
#banner {
width: 300px;
height: 300px;
position: relative;
background: #000;
border-radius: 50%;
overflow: hidden;
}
#banner::before {
content: '';
position: absolute;
background: #04ACFF;
width: 100%;
bottom: 0;
animation: wipe 5s cubic-bezier(.2,.6,.8,.4) forwards;
}
@keyframes wipe {
0% {
height: 0;
}
100% {
height: 100%;
}
}
<div id="banner">
</div>
@misterManSam의 훌륭한 대답 을 보완하는 네 가지 버전이 있습니다.
1. 완화로
설명
액체로 가득 찬 원형 그릇을 채우면 중간보다 아래쪽과 위쪽이 더 빨리 채워집니다 (더 넓은 중간 섹션을 덮을 영역이 더 많기 때문입니다). 따라서 이러한 조잡한 설명을 염두에두고 애니메이션은 빠르게 시작하고 중간에서 느리게 시작한 다음 그릇이 다시 상단에서 좁아지면 빠르게 완료되어야합니다.
이를 위해 CSS3 여유 함수를 사용할 수 있습니다 cubic-bezier(.2,.6,.8,.4)
..
아래의 예를보십시오.
( 이징을 조정하려면 여기에 훌륭한 리소스가 있습니다 : http://cubic-bezier.com/#.2,.6,.8,.4 )
예:
#banner {
width: 150px;
height: 150px;
position: relative;
background: #000;
border-radius: 50%;
overflow: hidden;
}
#banner::before {
content: '';
position: absolute;
background: #04ACFF;
width: 100%;
bottom: 0;
animation: wipe 5s cubic-bezier(.2,.6,.8,.4) forwards;
}
@keyframes wipe {
0% {
height: 0;
}
100% {
height: 100%;
}
}
<div id="banner">
</div>
2. SVG 맛
한 단계 더 나아가 자? CSS를 사용하여 "물"에 물결 모양의 표면을 추가하려면 어떻게해야합니까? 놀라운 SVG를 사용하여이를 수행 할 수 있습니다. Adobe Illustrator에서 물결 모양의 SVG 이미지를 만든 다음 별도의 CSS 애니메이션과 짜임새를 사용하여 루프에서 왼쪽에서 오른쪽으로 이동하도록 애니메이션했습니다.
예
#banner {
border-radius: 50%;
width: 150px;
height: 150px;
background: #000;
overflow: hidden;
backface-visibility: hidden;
transform: translate3d(0, 0, 0);
}
#banner .fill {
animation-name: fillAction;
animation-iteration-count: 1;
animation-timing-function: cubic-bezier(.2, .6, .8, .4);
animation-duration: 4s;
animation-fill-mode: forwards;
}
#banner #waveShape {
animation-name: waveAction;
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-duration: 0.5s;
width:300px;
height: 150px;
fill: #04ACFF;
}
@keyframes fillAction {
0% {
transform: translate(0, 150px);
}
100% {
transform: translate(0, -5px);
}
}
@keyframes waveAction {
0% {
transform: translate(-150px, 0);
}
100% {
transform: translate(0, 0);
}
}
<div id="banner">
<div class="fill">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="300px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve">
<path fill="#04ACFF" id="waveShape" d="M300,300V2.5c0,0-0.6-0.1-1.1-0.1c0,0-25.5-2.3-40.5-2.4c-15,0-40.6,2.4-40.6,2.4
c-12.3,1.1-30.3,1.8-31.9,1.9c-2-0.1-19.7-0.8-32-1.9c0,0-25.8-2.3-40.8-2.4c-15,0-40.8,2.4-40.8,2.4c-12.3,1.1-30.4,1.8-32,1.9
c-2-0.1-20-0.8-32.2-1.9c0,0-3.1-0.3-8.1-0.7V300H300z"/>
</svg>
</div>
</div>
3. 부어 라인
이 예에는 타설 선이 포함됩니다 (대부분의 그릇은 바닥이 아닌 상단에서 채움). 타설 선은 먼저 위에서 아래로 animation-delay
애니메이션되며 속성은 타설이 완료 될 때까지 채우기 애니메이션이 발생하지 않도록합니다.
#banner {
border-radius: 50%;
width: 150px;
height: 150px;
background: #000;
overflow: hidden;
backface-visibility: hidden;
transform: translate3d(0, 0, 0);
position: relative;
}
#banner .fill {
transform: translateY(150px);
animation-name: fillAction;
animation-iteration-count: 1;
animation-timing-function: cubic-bezier(.2, .6, .8, .4);
animation-duration: 4s;
animation-fill-mode: forwards;
animation-delay: 0.25s;
}
#banner .pour {
width: 6px;
position: absolute;
left: 50%;
margin-left: -3px;
bottom: 0;
top: 0;
background: #009ae6;
animation-name: pourAction;
animation-timing-function: linear;
animation-duration: 0.25s;
}
#banner #waveShape {
animation-name: waveAction;
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-duration: 0.5s;
width: 300px;
height: 150px;
fill: #04ACFF;
}
@keyframes pourAction {
0% {
transform: translateY(-100%);
}
100% {
transform: translateY(0);
}
}
@keyframes fillAction {
0% {
transform: translateY(150px);
}
100% {
transform: translateY(-5px);
}
}
@keyframes waveAction {
0% {
transform: translate(-150px, 0);
}
100% {
transform: translate(0, 0);
}
}
<div id="banner">
<div class="pour"></div>
<div class="fill">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="300px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve">
<path fill="#04ACFF" id="waveShape" d="M300,300V2.5c0,0-0.6-0.1-1.1-0.1c0,0-25.5-2.3-40.5-2.4c-15,0-40.6,2.4-40.6,2.4
c-12.3,1.1-30.3,1.8-31.9,1.9c-2-0.1-19.7-0.8-32-1.9c0,0-25.8-2.3-40.8-2.4c-15,0-40.8,2.4-40.8,2.4c-12.3,1.1-30.4,1.8-32,1.9
c-2-0.1-20-0.8-32.2-1.9c0,0-3.1-0.3-8.1-0.7V300H300z" />
</svg>
</div>
</div>
4. 진지한 블링 (아름다운 미학)
이 예제는 좀 더 사실적으로 보이도록 CSS에 몇 가지 속성을 더 추가합니다.
.bowl {
position: relative;
border-radius: 50%;
width: 150px;
height: 150px;
box-shadow: inset 0 -5px 0 0 rgba(0, 0, 0, 0.5), inset 0 -20px 5px 0 rgba(0, 0, 0, 0.2), inset -15px 0 5px 0 rgba(0, 0, 0, 0.1), inset 15px 0 5px 0 rgba(0, 0, 0, 0.1);
background: -moz-radial-gradient(center, ellipse cover, transparent 0%, transparent 76%, rgba(0, 0, 0, 0.65) 100%);
background: -webkit-radial-gradient(center, ellipse cover, transparent 0%, transparent 76%, rgba(0, 0, 0, 0.65) 100%);
background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 76%, rgba(0, 0, 0, 0.65) 100%);
margin: 20px;
}
.bowl:before {
overflow: hidden;
border-radius: 50%;
content: "";
box-shadow: inset 0 -5px 0 0 rgba(0, 0, 0, 0.5), inset 0 -20px 5px 0 rgba(0, 0, 0, 0.2), inset -15px 0 5px 0 rgba(0, 0, 0, 0.1), inset 15px 0 5px 0 rgba(0, 0, 0, 0.1);
background: -moz-radial-gradient(center, ellipse cover, transparent 0%, transparent 60%, rgba(0, 0, 0, 0.65) 81%, black 100%);
background: -webkit-radial-gradient(center, ellipse cover, transparent 0%, transparent 60%, rgba(0, 0, 0, 0.65) 81%, black 100%);
background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, 0.65) 81%, #000000 100%);
position: absolute;
width: 150px;
height: 150px;
z-index: 2;
}
.bowl:after {
content: "";
width: 60px;
border-radius: 50%;
height: 5px;
background: #039be4;
box-shadow: inset 0 0 10px 0 #000;
position: absolute;
left: 50%;
margin-left: -30px;
bottom: 0;
z-index: 2;
}
.bowl .inner {
border-radius: 50%;
width: 150px;
height: 150px;
background: -moz-radial-gradient(center, ellipse cover, transparent 0%, transparent 76%, rgba(0, 0, 0, 0.65) 100%);
background: -webkit-radial-gradient(center, ellipse cover, transparent 0%, transparent 76%, rgba(0, 0, 0, 0.65) 100%);
background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 76%, rgba(0, 0, 0, 0.65) 100%);
overflow: hidden;
-webkit-backface-visibility: hidden;
-webkit-transform: translate3d(0, 0, 0);
}
.bowl .inner:before {
content: "";
width: 20px;
height: 20px;
background: rgba(255, 255, 255, 0.2);
border-radius: 50%;
position: absolute;
right: 40%;
top: 60%;
z-index: 2;
}
.bowl .inner:after {
content: "";
width: 20px;
height: 40px;
background: rgba(255, 255, 255, 0.2);
border-radius: 50%;
position: absolute;
right: 30%;
top: 15%;
transform: rotate(-20deg);
z-index: 2;
}
.bowl .fill {
-webkit-animation-name: fillAction;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: cubic-bezier(0.2, 0.6, 0.8, 0.4);
-webkit-animation-duration: 4s;
-webkit-animation-fill-mode: forwards;
}
.bowl .waveShape {
-webkit-animation-name: waveAction;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-webkit-animation-duration: 0.5s;
width: 300px;
height: 150px;
fill: #039be4;
}
@-webkit-keyframes fillAction {
0% {
-webkit-transform: translate(0, 150px);
}
100% {
-webkit-transform: translate(0, 10px);
}
}
@-webkit-keyframes waveAction {
0% {
-webkit-transform: translate(-150px, 0);
}
100% {
-webkit-transform: translate(0, 0);
}
}
/* For aesthetics only ------------------------------------------*/
body {
margin: 0;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
}
h1 {
font: 200 1.2em "Segoe UI Light", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-weight: 200;
color: #fff;
background: #039be4;
padding: 20px;
margin: 0;
border-bottom: 10px solid #ccc;
}
h1 strong {
font-family: "Segoe UI Black";
font-weight: normal;
}
.explanation {
padding: 20px 40px;
float: right;
background: #e64a19;
-webkit-box-shadow: inset 0 30px 3px 0 rgba(0, 0, 0, 0.5);
box-shadow: inset 0 3px 5px 0 rgba(0, 0, 0, 0.2);
border-bottom: 10px solid #ccc;
max-width: 300px;
}
.explanation p {
color: #fff;
font-size: 0.8rem;
}
<div class="bowl">
<div class="inner">
<div class="fill">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="300px" viewBox="0 0 300 300" enable-background="new 0 0 300 300" xml:space="preserve">
<path class="waveShape" d="M300,300V2.5c0,0-0.6-0.1-1.1-0.1c0,0-25.5-2.3-40.5-2.4c-15,0-40.6,2.4-40.6,2.4
c-12.3,1.1-30.3,1.8-31.9,1.9c-2-0.1-19.7-0.8-32-1.9c0,0-25.8-2.3-40.8-2.4c-15,0-40.8,2.4-40.8,2.4c-12.3,1.1-30.4,1.8-32,1.9
c-2-0.1-20-0.8-32.2-1.9c0,0-3.1-0.3-8.1-0.7V300H300z" />
</svg>
</div>
</div>
</div>
나는 이것이 당신의 첫 번째 목표를 달성한다고 생각합니다.
#banner div:nth-child(2) {
-webkit-animation: wipe 6s;
-webkit-animation-delay: 0s;
-webkit-animation-direction: up;
-webkit-mask-size: 300px 3000px;
-webkit-mask-position: 300px 300px;
-webkit-mask-image: -webkit-gradient(linear, left bottom, left top,
color-stop(0.00, rgba(0,0,0,0)),
color-stop(0.25, rgba(0,0,0,0)),
color-stop(0.27, rgba(0,0,0,0)),
color-stop(0.80, rgba(0,0,0,1)),
color-stop(1.00, rgba(0,0,0,1)));
}
@-webkit-keyframes wipe {
0% {
-webkit-mask-position: 300px 300px;
}
100% {
-webkit-mask-position: 0 0;
}
}
div{
width: 200px;
height: 200px;
background: #ccc;
border-radius: 50%;
overflow: hidden;
position: relative;
z-index: 9;
}
div:before{
content: '';
position: absolute; top: 100%; left: 0;
width: 100%;
height: 100%;
background: #00BFFF;
-webkit-animation: animtop 5s forwards, animtop2 2s forwards;
animation: animtop 5s forwards, animtop2 2s forwards;
}
@-webkit-keyframes animtop{
0%{top: 100%;}
75%{top: 0}
}
@keyframes animtop{
0%{top: 100%;}
100%{top: 25%}
}
@-webkit-keyframes animtop2{
75%{top: 25%;}
100%{top: 0}
}
@keyframes animtop2{
75%{top: 25%;}
100%{top: 0}
}
<div></div>
여기에 Hover의 div에 물을 채우는 작업 코드 펜이 있습니다.
HTML
<div class="dot">
</div>
CSS
.dot {
border: 1px;
border-style: solid;
width: 100px;
height: 100px;
border-radius: 50%;
border-color: black;
color: black;
padding: 5px;
background-size: 200% 200%;
background-image:
linear-gradient(to top, #76daff 50%, transparent 50%);
transition: background-position 3000ms, color 3000ms ease, border-color 3000ms ease;
}
.dot:hover {
color: white;
border-color: black;
background-image:
linear-gradient(to top, #76daff 51%, transparent 50%);
background-position: 0 100%;
transition: background-position 3000ms, color 3000ms ease, border-color 3000ms ease;
}
https://codepen.io/ajitkumar96/pen/pOYbQm?editors=1100
참고URL : https://stackoverflow.com/questions/29738787/filling-water-animation
'Development Tip' 카테고리의 다른 글
각도 재질 대화 상자 영역 외부를 클릭하여 대화 상자를 닫습니다 (Angular 버전 4.0 이상 사용). (0) | 2020.12.06 |
---|---|
파이썬의 배열 필터? (0) | 2020.12.06 |
"On Error Resume Next"문은 무엇을합니까? (0) | 2020.12.06 |
div의 수직 정렬 이미지 (0) | 2020.12.06 |
이슈 탐색기에서 오류 만 표시하는 방법은 무엇입니까? (0) | 2020.12.06 |