08.09.2017
Анимация на anime.js иконки добавления в избранное
Отличный пример анимирования SVG объекта.
Анимация разбита на несколько блоков. Первым этапом анимируется серая звезда, которая скрывается, затем появляется круг, после цветная звезда с эффектом. Сделано очень интересно и данную библиотеку можно использовать в различных примерах для создания анимаций.
Анимация работает на anime.js, оригинал статьи: https://hackernoon.com/how-to-create-a-favorite-animation-with-anime-js-5f9ec02c80dd
<div class="favorite-align"> <div class="favorite"> <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"> <defs> <mask id="favorite__halo-mask"> <rect width="100%" height="100%" fill="white"/> <circle class="favorite__halo-inner" cx="50" cy="50" r="0" fill="black"></circle> </mask> </defs> <circle class="favorite__halo-outer" cx="50" cy="50" r="48" fill="#feb53c" mask="url(#favorite__halo-mask)"></circle> <path class="favorite__inactive" d="M50.214 10.067c6.4.204 10.753 25.648 10.753 25.648s26.256-1.803 27.13 2.857c.874 4.66-20.04 16.642-20.04 16.642s9.537 24.303 5.523 26.817c-4.015 2.515-23.545-14.023-23.545-14.023S29.333 84.493 25.633 81.785c-3.7-2.71 6.657-26.472 6.657-26.472S11.234 43.94 12.383 39.108c1.15-4.832 26.55-3.393 26.55-3.393s4.88-25.853 11.28-25.648z" fill="#dbdedd" fill-rule="evenodd"/> <path class="favorite__active" d="M50.214 10.067c6.4.204 10.753 25.648 10.753 25.648s26.256-1.803 27.13 2.857c.874 4.66-20.04 16.642-20.04 16.642s9.537 24.303 5.523 26.817c-4.015 2.515-23.545-14.023-23.545-14.023S29.333 84.493 25.633 81.785c-3.7-2.71 6.657-26.472 6.657-26.472S11.234 43.94 12.383 39.108c1.15-4.832 26.55-3.393 26.55-3.393s4.88-25.853 11.28-25.648z" fill="#feb53c" fill-rule="evenodd"/> </svg> <div class="favorite__sprinkle"><div class="favorite__sprinkle-circle"></div></div> <div class="favorite__sprinkle"><div class="favorite__sprinkle-circle"></div></div> <div class="favorite__sprinkle"><div class="favorite__sprinkle-circle"></div></div> <div class="favorite__sprinkle"><div class="favorite__sprinkle-circle"></div></div> <div class="favorite__sprinkle"><div class="favorite__sprinkle-circle"></div></div> </div> </div>
.favorite-align { text-align: center; } .favorite { position: relative; transform: scale(1); display: inline-block; transform-origin: 50% 0%; } .favorite__inactive { transform-origin: 50% 50%; } .favorite__active { transform-origin: 50% 50%; transform: scale(0); opacity: 1; } .favorite__halo-outer { transform-origin: 50% 50%; transform: scale(0); } .favorite__sprinkle { position: absolute; top: 50px; left: 52px; transform: rotate(36deg); } .favorite__sprinkle:nth-child(2) { transform: rotate(108deg); } .favorite__sprinkle:nth-child(3) { transform: rotate(180deg); } .favorite__sprinkle:nth-child(4) { transform: rotate(252deg); } .favorite__sprinkle:nth-child(5) { transform: rotate(324deg); } .favorite__sprinkle-circle { position: absolute; content: ''; background: #F98247; border-radius: 50%; width: 5px; height: 5px; margin-top: -28px; }
var timeline = anime.timeline({ autoplay: true, direction: 'normal', loop: true }); timeline .add({ targets: '.favorite__inactive', scale: { value: [1, 0], duration: 400, delay: 1000, easing: 'easeInQuad' } }) .add({ targets: '.favorite__halo-outer', scale: { value: [0, 1], duration: 400, delay: 1400, easing: 'easeOutQuad' }, offset: 0 }) .add({ targets: '.favorite__halo-inner', r: { value: [0, 49], duration: 300, delay: 1500, easing: 'easeOutQuad' }, offset: 0 }) .add({ targets: '.favorite__active', scale: { value: [0, 1], duration: 500, delay: 1600, easing: 'easeOutQuad' }, opacity: { value: 1, duration: 1500, delay: 2500 }, offset: 0 }) .add({ targets: '.favorite__sprinkle', opacity: { value: [0, 1], duration: 150, delay: 1500 }, offset: 0 }) .add({ targets: '.favorite__sprinkle-circle', height: { value: [5, 12], duration: 100, delay: 1600, easing: 'easeOutQuad' }, offset: 0 }) .add({ targets: '.favorite__sprinkle-circle', height: { value: [12, 5], duration: 100, delay: 1700, easing: 'easeOutQuad' }, offset: 0 }) .add({ targets: '.favorite__sprinkle-circle', opacity: { value: [1, 0], duration: 500, delay: 1800, easing: 'easeOutQuad' }, offset: 0 }) .add({ targets: '.favorite__sprinkle-circle', translateY: { value: [0, -28], duration: 500, delay: 1600, easing: 'easeOutQuad' }, offset: 0 });
Демонстрация
Нам будет приятно
Поделитесь
Комментарии