{"id":169,"date":"2011-05-26T20:56:17","date_gmt":"2011-05-27T03:56:17","guid":{"rendered":"http:\/\/adam.yanalunas.com\/blog\/?p=169"},"modified":"2011-05-26T21:03:28","modified_gmt":"2011-05-27T04:03:28","slug":"using-css-transforms-to-mimic-safaris-find-word-selection","status":"publish","type":"post","link":"http:\/\/adam.yanalunas.com\/blog\/archives\/169","title":{"rendered":"Using CSS transforms to mimic Safari&#8217;s find word selection"},"content":{"rendered":"<p>Here&#8217;s a quick one for you kids. I&#8217;ve just started playing with CSS3 and I needed something simple but useful to implement. Say what you will about Safari as a browser but I think its find feature has the best UI for showing matching results on the page and what item is currently selected. Wait, you don&#8217;t use Safari? Okay, check out the picture below.<\/p>\n<p class=\"center\"><a href=\"http:\/\/adam.yanalunas.com\/blog\/wp-content\/uploads\/2011\/05\/Safari-find-screnshot.png\"><img loading=\"lazy\" src=\"http:\/\/adam.yanalunas.com\/blog\/wp-content\/uploads\/2011\/05\/Safari-find-screnshot.png\" alt=\"\" title=\"Safari find screnshot\" width=\"454\" height=\"186\" class=\"alignnone size-full wp-image-171\" srcset=\"http:\/\/adam.yanalunas.com\/blog\/wp-content\/uploads\/2011\/05\/Safari-find-screnshot.png 454w, http:\/\/adam.yanalunas.com\/blog\/wp-content\/uploads\/2011\/05\/Safari-find-screnshot-300x122.png 300w\" sizes=\"(max-width: 454px) 100vw, 454px\" \/><\/a><\/p>\n<p>See what I&#8217;m saying? Fade out what isn&#8217;t important, lighten all matches, put some special pizazz on the current item. As an added bonus each time you switch the current item it &#8220;pops&#8221; a bit to help pull your eye to where the next item is. Pretty slick. <\/p>\n<p>I set out not to duplicate the styles but to get a feel for CSS3 animation and transitions. With that in mind the animation tweens and colors aren&#8217;t exact but they&#8217;ll work for the project I have in mind. If you have improvements go ahead and share them in the comments.<\/p>\n<p><strong>[Ninja edit]<\/strong> I forgot to mention that in order for CSS transformations to be hardware accelerated by devices that do so you have to include the &#8220;translate3d&#8221; property. If you don&#8217;t need to translate, use the meaningless zeroed out setting like I did below.<\/p>\n<p><strong>[Ninja edit 2}<\/strong> Also, I didn&#8217;t bother putting in all the different vendor prefixes. If you&#8217;re interested in this code your Google-fu will be strong enough to look up the different vendor settings and adjust accordingly.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n@-webkit-keyframes pulseFocusedOverlay {\r\n\t0%, 100% {\r\n\t\t-webkit-transform: scale(1) translate3d(0px, 0px, 0px);;\r\n\t}\r\n\t15% {\r\n\t\t-webkit-transform: scale(1.35) translate3d(0px, 0px, 0px);;\r\n\t}\r\n}\r\n\r\n.searchMatch {\r\n\tdisplay: inline-block;\r\n\tpadding: 0 4px;\r\n\tmargin: 0 -3px;\r\n\t-webkit-box-shadow: 0 1px 5px #333;\r\n\tbox-shadow: 0 1px 5px #333;\r\n\tcolor: #222;\r\n\tbackground-image: -webkit-gradient(linear, left bottom, left top, color-stop(.5, rgb(222, 222, 222)), color-stop(1, rgb(255, 255, 255)));\r\n}\r\n\r\n.searchMatch_selected {\r\n\tdisplay: inline-block;\r\n\tpadding: 0 4px;\r\n\tborder-radius: 5px;\r\n\tborder: 1px solid #EFDB13;\r\n\tmargin: -1px -4px;\r\n\t-webkit-box-shadow: 0 1px 3px #333;\r\n\tbox-shadow: 0 1px 5px #333;\r\n\tcolor: #000;\r\n\t-webkit-animation: pulseFocusedOverlay 185ms ease-in-out 0;\r\n\tbackground-image: -webkit-gradient(linear, left bottom,left top,color-stop(.5, rgb(238, 207, 0)),color-stop(1, rgb(242, 237, 19)));\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a quick one for you kids. I&#8217;ve just started playing with CSS3 and I needed something simple but useful to implement. Say what you will about Safari as a browser but I think its find feature has the best UI for showing matching results on the page and what item is currently selected. Wait, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/posts\/169"}],"collection":[{"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/comments?post=169"}],"version-history":[{"count":5,"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":175,"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/posts\/169\/revisions\/175"}],"wp:attachment":[{"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/media?parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/categories?post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/adam.yanalunas.com\/blog\/wp-json\/wp\/v2\/tags?post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}