2015-11-17 4 views
4

Я работаю над анимацией рисования линии SVG, как показано ниже.Как управлять временем анимации CSS3

enter image description here

Так что я делаю это анимировать ухо с помощью stroke-dasharray и по-прежнему с точками.

Мне удалось закончить рисунок уха, но я не знаю, как контролировать время точек. Ниже приведены мои анимации шаги:

  1. Ear рисунок анимации в 5s
  2. После 5 секунд, по-прежнему с анимацией точек (анимировать построчно)
  3. Когда Закончите точки анимации, петля обратно на 1-й ступени

Это мой код, но он постепенно мигает. Как настроить время?

.firstpath { 
 
    stroke-dasharray: 1500; 
 
    animation: firstanimate 5s linear forwards infinite; 
 
} 
 
@keyframes firstanimate { 
 
    from { 
 
    stroke-dashoffset: 1500; 
 
    } 
 
    to { 
 
    stroke-dashoffset: 0; 
 
    } 
 
} 
 
.secondpath { 
 
    stroke-dasharray: 500; 
 
    animation: secondanimate 5s linear forwards infinite; 
 
} 
 
@keyframes secondanimate { 
 
    from { 
 
    stroke-dashoffset: 500; 
 
    } 
 
    to { 
 
    stroke-dashoffset: 0; 
 
    } 
 
} 
 
.thirdpath { 
 
    stroke-dasharray: 500; 
 
    animation: thirdanimate 5s linear forwards infinite; 
 
} 
 
@keyframes thirdanimate { 
 
    from { 
 
    stroke-dashoffset: 500; 
 
    } 
 
    to { 
 
    stroke-dashoffset: 0; 
 
    } 
 
} 
 
.row1col1 { 
 
    animation-delay: 1s; 
 
    animation: blink 2s step-start 0s infinite; 
 
    -webkit-animation: blink 2s step-start 0s infinite; 
 
} 
 
@keyframes blink { 
 
    0% { 
 
    opacity: 1.0; 
 
    } 
 
    50% { 
 
    opacity: 0.0; 
 
    } 
 
    100% { 
 
    opacity: 1.0; 
 
    } 
 
} 
 
@-webkit-keyframes blink { 
 
    0% { 
 
    opacity: 1.0; 
 
    } 
 
    50% { 
 
    opacity: 0.0; 
 
    } 
 
    100% { 
 
    opacity: 1.0; 
 
    } 
 
}
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="841.89px" height="595.28px" viewBox="0 0 841.89 595.28" enable-background="new 0 0 841.89 595.28" xml:space="preserve"> 
 

 
    <g> 
 
    <path class="firstpath" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d=" 
 
\t \t \t M253.441,284.167c0,0-0.883-14.535,15.429-18.551c5.364-1.32,15.943-0.665,21.667,6.79c13.859,18.051-3.235,32.286-8.087,37.262 
 
\t \t \t c-4.853,4.979-7.713,21.027-17.543,20.528c-9.829-0.497-12.69-6.717-12.317-11.818" /> 
 

 
    <path class="secondpath" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d=" 
 
\t \t \t M285.249,285.252c0,0,0.654-8.212-8.864-10.544c-9.519-2.334-16.796,8.211-10.825,17.449c2.613-1.12,5.226,0.652,5.599,2.52 
 
\t \t \t c0.373,1.866-1.213,4.199-3.826,4.199" /> 
 

 
    <path class="thirdpath" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d=" 
 
\t \t \t M257.815,307.553c0,0-3.732,5.879,2.333,8.118c6.065,2.241,5.318-8.118,8.865-9.237c3.545-1.119,11.943-2.519,11.943-10.265 
 
\t \t \t c0-7.744-6.398-16.451-17.522-11.958" /> 
 
    </g> 
 

 
    <line class="row1col1" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="319.41" y1="287.987" x2="324.156" y2="286.627" /> 
 

 
    <line fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="328.667" y1="285.335" x2="332.744" y2="284.167" /> 
 

 
    <line fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="338.25" y1="301.171" x2="343.41" y2="301.171" /> 
 

 
    <line fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="328.667" y1="301.171" x2="333.75" y2="301.171" /> 
 

 
    <line fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="319.41" y1="301.171" x2="324.156" y2="301.171" /> 
 

 
    <line fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="313.741" y1="314.625" x2="319.41" y2="315.987" /> 
 

 
    <line fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="323.741" y1="316.746" x2="329.667" y2="318.142" /> 
 

 
</svg>

+0

Я надеюсь, что обновленный фрагмент кода в моем ответе полностью решить вашу проблему. Если да, пожалуйста, подумайте о том, чтобы принять ответ (щелкните по пустому тику ниже кнопок голосования рядом с ответом). Обычно мы отмечаем проблему как * решаемую * здесь. – Harry

+0

Да, вы сделали. Но мне нужно настроить время, чтобы сделать его быстрее. Большое вам спасибо за ваш ответ. Проголосовал вчера. – Eelyn

+1

Извините, неправильно понимаю, я думал, вы сказали о голосовании. Я щелкнул его, потому что ваш ответ решил мою проблему. :) – Eelyn

ответ

3

Путь образуются части формы, для этого потребуется несколько ключевых кадров анимации, чтобы работать так, как вы собираетесь за это.

Ниже то, что вы должны сделать:

  • Ухо анимации, хотя, как ожидается, завершить на 5s отметки не следует начинать свою следующую итерацию до анимации линий завершены. То есть, ухо должно оставаться бездействующим в течение времени, затраченного линиями, чтобы завершить анимацию. Следовательно, мы должны установить animation-duration для уха таким образом, чтобы он покрывал количество времени, необходимое для завершения линий для их анимации. Здесь каждый компонент линии принимает 1s, и поэтому итоговые animation-duration для всех элементов (ушей и линий) будут 12s.
  • Анимация уха должна быть заполнена на отметке 5s (из общей продолжительности 12s), и поэтому значение ключевого кадра from - to должно быть заменено процентами. Ухо анимация должна начинаться с 0% и достичь ее завершения в 41% (что примерно равно знаку 5s). Оттуда он должен удерживать свое положение до отметки 100% (12s) (это в основном до тех пор, пока линии не завершили свою анимацию).
  • Каждый компонент линии должен начинаться после того, как их предыдущая часть завершила свою анимацию, и поэтому row1col1 должен начинаться с 41%, когда ухо становится полностью видимым (до этого момента он должен оставаться невидимым).
  • В row1col1 потребности 1s анимации (что примерно 8% из 12s) и, следовательно, row1col2 должен ждать, пока 49% от общей длительности, чтобы начать свою анимацию. Аналогично row2col1 должно начинаться с 57%, row2col2 должно начинаться с 66% и так далее.
  • Если линии необходимо медленно исчезать, а затем сделать его начать с opacity: 0 в 41% и получить opacity: 1 в 49% (для row1col1 и так далее для остальных). С другой стороны, если вам нужно, чтобы они появлялись мгновенно, уменьшите процент, когда он получит opacity: 1. В фрагменте я сделал row1col1 досягаемости opacity: 1 по адресу 42% (что похоже на 0.12s).

Примечание:

  • Я также изменил stroke-dasharray параметров компонентов уха, чтобы избежать задержек, которая была первоначально там между завершением анимации уха и началом анимации линии.
  • Я также рекомендую вам получить помощь эксперта SVG, чтобы проверить, нет ли. частей можно свести к минимуму, так как это уменьшит количество. требуемых ключевых кадров и т. д. К сожалению, мои знания SVG ограничены, и поэтому я не могу с этим справиться.

.firstpath { 
 
    stroke-dasharray: 150; 
 
    animation: firstanimate 12s linear forwards infinite; 
 
} 
 
@keyframes firstanimate { 
 
    0% { 
 
    stroke-dashoffset: 150; 
 
    } 
 
    41% { 
 
    stroke-dashoffset: 0; 
 
    } 
 
} 
 
.secondpath { 
 
    stroke-dasharray: 100; 
 
    animation: secondanimate 12s linear forwards infinite; 
 
} 
 
@keyframes secondanimate { 
 
    0% { 
 
    stroke-dashoffset: 100; 
 
    } 
 
    41% { 
 
    stroke-dashoffset: 0; 
 
    } 
 
} 
 
.thirdpath { 
 
    stroke-dasharray: 65; 
 
    animation: thirdanimate 12s linear forwards infinite; 
 
} 
 
@keyframes thirdanimate { 
 
    0% { 
 
    stroke-dashoffset: 65; 
 
    } 
 
    41% { 
 
    stroke-dashoffset: 0; 
 
    } 
 
} 
 
line { 
 
    opacity: 0; 
 
} 
 
.row1col1 { 
 
    animation: blink 12s linear forwards infinite; 
 
} 
 
@keyframes blink { 
 
    41% { 
 
    opacity: 0; 
 
    } 
 
    42%, 100% { 
 
    opacity: 1; 
 
    } 
 

 
} 
 
.row1col2 { 
 
    animation: blink2 12s linear forwards infinite; 
 
} 
 
@keyframes blink2 { 
 
    49% { 
 
    opacity: 0; 
 
    } 
 
    50%, 100% { 
 
    opacity: 1; 
 
    } 
 
} 
 
.row2col1 { 
 
    animation: blink3 12s linear forwards infinite; 
 
} 
 
@keyframes blink3 { 
 
    57% { 
 
    opacity: 0; 
 
    } 
 
    58%, 100% { 
 
    opacity: 1; 
 
    } 
 
} 
 
.row2col2 { 
 
    animation: blink4 12s linear forwards infinite; 
 
} 
 
@keyframes blink4 { 
 
    66% { 
 
    opacity: 0; 
 
    } 
 
    67%, 100% { 
 
    opacity: 1; 
 
    } 
 
} 
 
.row2col3 { 
 
    animation: blink5 12s linear forwards infinite; 
 
} 
 
@keyframes blink5 { 
 
    75% { 
 
    opacity: 0; 
 
    } 
 
    76%, 100% { 
 
    opacity: 1; 
 
    } 
 
} 
 
.row3col1 { 
 
    animation: blink6 12s linear forwards infinite; 
 
} 
 
@keyframes blink6 { 
 
    84% { 
 
    opacity: 0; 
 
    } 
 
    85%, 100% { 
 
    opacity: 1; 
 
    } 
 
} 
 

 
.row3col2 { 
 
    animation: blink7 12s linear forwards infinite; 
 
} 
 
@keyframes blink7 { 
 
    92% { 
 
    opacity: 0; 
 
    } 
 
    93%, 100% { 
 
    opacity: 1; 
 
    } 
 
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script> 
 
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="841.89px" height="595.28px" viewBox="0 0 841.89 595.28" enable-background="new 0 0 841.89 595.28" xml:space="preserve"> 
 

 
    <g> 
 
    <path class="firstpath" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d=" 
 
\t \t \t M253.441,284.167c0,0-0.883-14.535,15.429-18.551c5.364-1.32,15.943-0.665,21.667,6.79c13.859,18.051-3.235,32.286-8.087,37.262 
 
\t \t \t c-4.853,4.979-7.713,21.027-17.543,20.528c-9.829-0.497-12.69-6.717-12.317-11.818" /> 
 

 
    <path class="secondpath" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d=" 
 
\t \t \t M285.249,285.252c0,0,0.654-8.212-8.864-10.544c-9.519-2.334-16.796,8.211-10.825,17.449c2.613-1.12,5.226,0.652,5.599,2.52 
 
\t \t \t c0.373,1.866-1.213,4.199-3.826,4.199" /> 
 

 
    <path class="thirdpath" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d=" 
 
\t \t \t M257.815,307.553c0,0-3.732,5.879,2.333,8.118c6.065,2.241,5.318-8.118,8.865-9.237c3.545-1.119,11.943-2.519,11.943-10.265 
 
\t \t \t c0-7.744-6.398-16.451-17.522-11.958" /> 
 
    </g> 
 

 
    <line class="row1col1" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="319.41" y1="287.987" x2="324.156" y2="286.627" /> 
 

 
    <line class="row1col2" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="328.667" y1="285.335" x2="332.744" y2="284.167" /> 
 

 
    <line class="row2col3" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="338.25" y1="301.171" x2="343.41" y2="301.171" /> 
 

 
    <line class="row2col2" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="328.667" y1="301.171" x2="333.75" y2="301.171" /> 
 

 
    <line class="row2col1" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="319.41" y1="301.171" x2="324.156" y2="301.171" /> 
 

 
    <line class="row3col1" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="313.741" y1="314.625" x2="319.41" y2="315.987" /> 
 

 
    <line class="row3col2" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="323.741" y1="316.746" x2="329.667" y2="318.142" /> 
 

 
</svg>

+0

Ничего себе, круто! Это то, чего я хочу. Спасибо огромное! Как удалить эффект затухания в эффекте выцветания? – Eelyn

+0

@Eelyn: Извините, не получил то, о чем вы говорите, эффектом постепенного затухания. Вы хотите, чтобы линии появлялись мгновенно, а не исчезали? – Harry

+0

Да, это то, что я имею в виду. Извините, потому что я не объяснил это четко. – Eelyn

1

Вы можете играть со временем анимации. Задержка срабатывает только для первой анимации. Вы также должны перенести свойства без префикса на передний план.

Я сделал анимацию, которая мигает через 2 секунды каждые 5 секунд (всего 5 секунд).

.firstpath { 
 
    stroke-dasharray: 1500; 
 
    animation: firstanimate 5s linear forwards infinite; 
 
} 
 

 
@keyframes firstanimate { 
 
    from { stroke-dashoffset: 1500; } 
 
    to { stroke-dashoffset: 0; } 
 
} 
 

 
.secondpath { 
 
    stroke-dasharray: 500; 
 
    animation: secondanimate 5s linear forwards infinite; 
 
} 
 

 
@keyframes secondanimate { 
 
    from { stroke-dashoffset: 500; } 
 
    to { stroke-dashoffset: 0; } 
 
} 
 

 
.thirdpath { 
 
    stroke-dasharray: 500; 
 
    animation: thirdanimate 5s linear forwards infinite; 
 
} 
 

 
@keyframes thirdanimate { 
 
    from { stroke-dashoffset: 500; } 
 
    to { stroke-dashoffset: 0; } 
 
} 
 

 

 
.row1col1 { 
 
    animation: blink1 5s step-start 0s infinite; 
 
    -webkit-animation: blink1 5s step-start 0s infinite; 
 
} 
 
@-webkit-keyframes blink1 { 
 
    0% { 
 
    opacity: 1.0; 
 
    } 
 
    70% { 
 
    opacity: 1.0; 
 
    } 
 
    
 
    80% { 
 
    opacity: 0.0; 
 
    } 
 
    
 
    100% { 
 
    opacity: 1.0; 
 
    } 
 
} 
 

 
@keyframes blink1 { 
 
    0% { 
 
    opacity: 1.0; 
 
    } 
 
    70% { 
 
    opacity: 1.0; 
 
    } 
 
    80% { 
 
    opacity: 0.0; 
 
    } 
 
    
 
    100% { 
 
    opacity: 1.0; 
 
    } 
 
} 
 

 
.row1col2 { 
 
    animation: blinkl2 5s step-start 0s infinite; 
 
    -webkit-animation: blink2 5s step-start 0s infinite; 
 
} 
 
@-webkit-keyframes blink2 { 
 
    0% { 
 
    opacity: 1.0; 
 
    } 
 
    80% { 
 
    opacity: 1.0; 
 
    } 
 
    
 
    90% { 
 
    opacity: 0.0; 
 
    } 
 
    
 
    100% { 
 
    opacity: 1.0; 
 
    } 
 
} 
 
@keyframes blink2 { 
 
    0% { 
 
    opacity: 1.0; 
 
    } 
 
    80% { 
 
    opacity: 1.0; 
 
    } 
 
    
 
    90% { 
 
    opacity: 0.0; 
 
    } 
 
    
 
    100% { 
 
    opacity: 1.0; 
 
    } 
 
} 
 
.row1col3 { 
 
    animation: blinkl3 5s step-start 0s infinite; 
 
    -webkit-animation: blink3 5s step-start 0s infinite; 
 
} 
 
@-webkit-keyframes blink2 { 
 
    0% { 
 
    opacity: 1.0; 
 
    } 
 
    90% { 
 
    opacity: 1.0; 
 
    } 
 
    
 
    95% { 
 
    opacity: 0.0; 
 
    } 
 
    
 
    100% { 
 
    opacity: 1.0; 
 
    } 
 
} 
 
@keyframes blink3 { 
 
    0% { 
 
    opacity: 1.0; 
 
    } 
 
    90% { 
 
    opacity: 1.0; 
 
    } 
 
    
 
    95% { 
 
    opacity: 0.0; 
 
    } 
 
    
 
    100% { 
 
    opacity: 1.0; 
 
    } 
 
}
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" 
 
\t width="841.89px" height="595.28px" viewBox="0 0 841.89 595.28" enable-background="new 0 0 841.89 595.28" xml:space="preserve"> 
 
\t 
 
\t <g> 
 
\t \t <path class="firstpath" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d=" 
 
\t \t \t M253.441,284.167c0,0-0.883-14.535,15.429-18.551c5.364-1.32,15.943-0.665,21.667,6.79c13.859,18.051-3.235,32.286-8.087,37.262 
 
\t \t \t c-4.853,4.979-7.713,21.027-17.543,20.528c-9.829-0.497-12.69-6.717-12.317-11.818"/> 
 
\t \t \t 
 
\t \t <path class="secondpath" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d=" 
 
\t \t \t M285.249,285.252c0,0,0.654-8.212-8.864-10.544c-9.519-2.334-16.796,8.211-10.825,17.449c2.613-1.12,5.226,0.652,5.599,2.52 
 
\t \t \t c0.373,1.866-1.213,4.199-3.826,4.199"/> 
 
\t \t \t 
 
\t \t <path class="thirdpath" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d=" 
 
\t \t \t M257.815,307.553c0,0-3.732,5.879,2.333,8.118c6.065,2.241,5.318-8.118,8.865-9.237c3.545-1.119,11.943-2.519,11.943-10.265 
 
\t \t \t c0-7.744-6.398-16.451-17.522-11.958"/> 
 
\t </g> 
 

 
\t <line class="row1col1" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="319.41" y1="287.987" x2="324.156" y2="286.627"/> 
 

 
\t <line class="row1col2" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="328.667" y1="285.335" x2="332.744" y2="284.167"/> 
 

 
\t <line class="row1col3" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="338.25" y1="301.171" x2="343.41" y2="301.171"/> 
 

 
\t <line class="row1col2" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="328.667" y1="301.171" x2="333.75" y2="301.171"/> 
 

 
\t <line class="row1col1" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="319.41" y1="301.171" x2="324.156" y2="301.171"/> 
 

 
\t <line class="row1col1" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="313.741" y1="314.625" x2="319.41" y2="315.987"/> 
 

 
\t <line class="row1col2" fill="none" stroke="#000000" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" x1="323.741" y1="316.746" x2="329.667" y2="318.142"/>

+0

Классно! Огромное спасибо. Я сам настрою анимацию. – Eelyn

 Смежные вопросы

  • Нет связанных вопросов^_^