{"id":3593,"date":"2014-02-12T15:42:44","date_gmt":"2014-02-12T20:42:44","guid":{"rendered":"http:\/\/blog.cmiscm.com\/?p=3593"},"modified":"2023-01-03T16:29:47","modified_gmt":"2023-01-04T00:29:47","slug":"improve-masking-effect-performance-on-mobile-devices","status":"publish","type":"post","link":"http:\/\/blog.cmiscm.com\/?p=3593","title":{"rendered":"Improve masking effect performance on mobile devices"},"content":{"rendered":"<p>If you want to make a masking animation on HTML, usually can make using height transition and overflow: hidden.<br \/>\nIt&#8217;s fine on your desktop browser, but it&#8217;s not smooth on mobile devices.<br \/>\nThe performance of animating some elements (such as width, height, left, top and margin..etc) are not that great on mobile devices.<br \/>\nThe best things for smooth animation are CSS3 transitions, CSS3 3D transforms, Canvas Drawing and WebGL, because these things are using GPU acceleration.<br \/>\nI&#8217;ve tested three ways (Height, ScaleY, Translate) for smooth animations, you can see my demo at below url.<br \/>\n<a href=\"http:\/\/lab.cmiscm.com\/masking\/\" target=\"_blank\" rel=\"noopener\">http:\/\/lab.cmiscm.com\/masking\/<\/a><\/p>\n<h3 style=\"margin:80px 0 10px 0;\">1. Height animation<\/h3>\n<p>It&#8217;s very simple way for the masking animation.<br \/>\nBut the performance is bad on mobile devices, the animation is not smooth.<\/p>\n<div class=\"stitle\" style=\"margin-top:20px;\">RUNNING ON IPHONE<\/div>\n<div style=\"margin:0 0 0 0;\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.cmiscm.com\/wp-content\/uploads\/2014\/02\/height3.gif\" alt=\"height\" width=\"320\" height=\"480\" class=\"alignnone size-full wp-image-3602\"><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;\">DEMO<\/div>\n<div style=\"margin:0 0 0 0;\"><a href=\"http:\/\/lab.cmiscm.com\/masking\/height.html\" target=\"_blank\" rel=\"noopener\">http:\/\/lab.cmiscm.com\/masking\/height.html<\/a><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;margin-bottom:-12px;\">CSS<\/div>\n<div class=\"des\"><script src=\"https:\/\/gist.github.com\/cmiscm\/8197afcfd28b34a3e0d485ad9cf28e63.js\"><\/script><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;margin-bottom:-12px;\">HTML<\/div>\n<div class=\"des\"><script src=\"https:\/\/gist.github.com\/cmiscm\/1280614d9e8cf125435dbf20d0672fcc.js\"><\/script><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;margin-bottom:-12px;\">JS<\/div>\n<div class=\"des\"><script src=\"https:\/\/gist.github.com\/cmiscm\/b47cef010c37192d30296de6e663bce6.js\"><\/script><\/div>\n<h3 style=\"margin:80px 0 10px 0;\">2. Scale animation<\/h3>\n<p>So what about using scaleY for the masking animation.<br \/>\nThe performance is good, but the image is stretched little bit while animating.<\/p>\n<div class=\"stitle\" style=\"margin-top:20px;\">RUNNING ON IPHONE<\/div>\n<div style=\"margin:0 0 0 0;\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.cmiscm.com\/wp-content\/uploads\/2014\/02\/scale.gif\" alt=\"scale\" width=\"320\" height=\"480\" class=\"alignnone size-full wp-image-3605\"><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;\">DEMO<\/div>\n<div style=\"margin:0 0 0 0;\"><a href=\"http:\/\/lab.cmiscm.com\/masking\/scale.html\" target=\"_blank\" rel=\"noopener\">http:\/\/lab.cmiscm.com\/masking\/scale.html<\/a><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;margin-bottom:-12px;\">CSS<\/div>\n<div class=\"des\"><script src=\"https:\/\/gist.github.com\/cmiscm\/23e1799fecba34c55ffec0278a9d3630.js\"><\/script><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;margin-bottom:-12px;\">HTML<\/div>\n<div class=\"des\"><script src=\"https:\/\/gist.github.com\/cmiscm\/0d3a8463d873f7cf4f6e9ba3e5b3777e.js\"><\/script><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;margin-bottom:-12px;\">JS<\/div>\n<div class=\"des\"><script=\"\" src=\"https:\/\/gist.github.com\/cmiscm\/452f609437b10029fc7b1a9660254030.js\"><\/script=\"\"><\/div>\n<h3 style=\"margin:80px 0 10px 0;\">3. Translate animation<\/h3>\n<p>Actually this is what I want to say at this article.<br \/>\nIt only uses CSS transitions with two masking layers, and it&#8217;s super smooth on mobile devices.<\/p>\n<div style=\"overflow:hidden;\">\n<div style=\"float:left;margin:20px 80px 0 0;\">\n<div class=\"stitle\">RUNNING ON IPHONE<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.cmiscm.com\/wp-content\/uploads\/2014\/02\/translate.gif\" alt=\"translate\" width=\"320\" height=\"480\" class=\"alignnone size-full wp-image-3604\"><\/p>\n<\/div>\n<div style=\"float:left;margin:20px 0 0 0;\">\n<div class=\"stitle\">LAYER DEPTH<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.cmiscm.com\/wp-content\/uploads\/2014\/02\/masking.gif\" alt=\"masking\" width=\"320\" height=\"480\" class=\"alignnone size-full wp-image-3598\"><\/p>\n<\/div>\n<\/div>\n<div class=\"stitle\" style=\"margin-top:20px;clear:both;\">DEMO<\/div>\n<div style=\"margin:0 0 0 0;\"><a href=\"http:\/\/lab.cmiscm.com\/masking\/translate.html\" target=\"_blank\">http:\/\/lab.cmiscm.com\/masking\/translate.html<\/a><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;margin-bottom:-12px;\">CSS<\/div>\n<div class=\"des\"><script src=\"https:\/\/gist.github.com\/cmiscm\/5652a57c5ae9f612b9a92aad03b15c28.js\"><\/script><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;margin-bottom:-12px;\">HTML<\/div>\n<div class=\"des\"><script src=\"https:\/\/gist.github.com\/cmiscm\/7ac38d537e27c8c9476312b163034ae0.js\"><\/script><\/div>\n<div class=\"stitle\" style=\"margin-top:20px;margin-bottom:-12px;\">JS<\/div>\n<div class=\"des\"><script src=\"https:\/\/gist.github.com\/cmiscm\/e78381945d08b96b3aa36eea5f67d966.js\"><\/script><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you want to make a masking animation on HTML, usually can make using height transition and overflow: hidden. It&#8217;s fine on your desktop browser, but it&#8217;s not smooth on mobile devices. The performance of animating some elements (such as width, height, left, top and margin..etc) are not that great on mobile devices. The best [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[352],"tags":[315,314,408,407],"class_list":["post-3593","post","type-post","status-publish","format-standard","hentry","category-lab","tag-css","tag-html","tag-js","tag-masking"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/blog.cmiscm.com\/index.php?rest_route=\/wp\/v2\/posts\/3593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.cmiscm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.cmiscm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.cmiscm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.cmiscm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3593"}],"version-history":[{"count":0,"href":"http:\/\/blog.cmiscm.com\/index.php?rest_route=\/wp\/v2\/posts\/3593\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.cmiscm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.cmiscm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3593"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.cmiscm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}