path<\/code> element to show the level of volume. For this, we\u2019ll create a method which switches its CSS class according to the volume level.<\/p>\n<svg @click=\"changeVolume\">\r\n\t<g :class=\"`level-${volumeLevel}`\">\r\n\t\t<path d=\"...\"\/> <!-- volume level 1 -->\r\n\t\t<path d=\"...\"\/> <!-- volume level 2 -->\r\n\t\t<path d=\"...\"\/> <!-- volume level 3 -->\r\n\t\t<polygon points=\"...\"\/>\r\n\t<\/g>\r\n<\/svg><\/code><\/pre>\nBased on this class, we can show and hide certain path<\/code> elements as:<\/p>\npath {\r\n\topacity: 0;\r\n\ttransform-origin: left;\r\n\ttransform: translateX(-5px) scale(0.6);\r\n\ttransition: transform 0.25s, opacity 0.2s;\r\n}\r\n\r\n.level-1 path:first-child,\r\n.level-2 path:first-child,\r\n.level-2 path:nth-child(2),\r\n.level-3 path {\r\n\topacity: 1;\r\n\ttransform: none;\r\n}<\/code><\/pre>\nThe animated volume control<\/figcaption><\/figure>\nSecond micro-interaction: The favorite icon<\/h4>\n Do you like it when you click on Twitter\u2019s heart button? That\u2019s because it feels unique and special by the way it animates on click. We\u2019ll make something similar but real quick. For this, we first get an SVG heart icon and add it to the the markup. Then we\u2019ll add a bouncy animation to it that\u2019s triggered on click.<\/p>\n
@keyframes bounce {\r\n\t0%, 100% {\r\n\t\ttransform: none;\r\n\t}\r\n\t30% {\r\n\t\ttransform: scale(1.3);\r\n\t}\r\n\t60% {\r\n\t\ttransform: scale(0.9);\r\n\t}\r\n}<\/code><\/pre>\nAnother fun thing we can do is add other small heart icons around it with random sizes and positions. Ideally, we\u2019d add a few absolute<\/code>-positioned HTML elements that a heart as the background. Let\u2019s Arrange each of them as below by setting their left<\/code> and bottom<\/code> values.<\/p>\nWe\u2019ll also include a fade away effect so the icons appear to dissolve as they move upward by adding a keyframe animation on the same click event.<\/p>\n
@keyframes float-upwards {\r\n\t0%, 100% {\r\n\t\topacity: 0;\r\n\t}\r\n\t50% {\r\n\t\topacity: 0.7;\r\n\t}\r\n\t50%, 100% {\r\n\t\ttransform: translate(-1px, -5px);\r\n\t}\r\n}<\/code><\/pre>\nThe animated favorite button<\/figcaption><\/figure>\nSumming up<\/h3>\n That\u2019s all! I hope you find all this motivating to try animations on your own websites and projects.<\/p>\n
While writing this, I also wanted to expand on the fundamental animation principles we glossed over earlier because I believe that they help choose animation durations, and avoid non-meaningful animations. That\u2019s important to discuss because doing animations correctly<\/strong> is better than doing them at all. But this sounds like a whole another topic to be covered in a future article.<\/p>\n","protected":false},"excerpt":{"rendered":"Web animation is one of the factors that can strongly enhance your website\u2019s look and feel. Sadly, unlike mobile apps, there aren\u2019t as many websites using animation to their benefit as you would think. We don\u2019t want to count yours among those, so this article is for you and anyone else looking for ways to […]<\/p>\n","protected":false},"author":257922,"featured_media":283390,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":"","jetpack_publicize_message":"\u2728Writing Animations That Bring Your Site to Life \u2728","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[4],"tags":[708,932],"jetpack_publicize_connections":[],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2019\/02\/feat-1.png?fit=2880%2C1594&ssl=1","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/283132"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/257922"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=283132"}],"version-history":[{"count":14,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/283132\/revisions"}],"predecessor-version":[{"id":283512,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/283132\/revisions\/283512"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media\/283390"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=283132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/categories?post=283132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=283132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}