{"id":1272,"date":"2016-12-28T20:43:43","date_gmt":"2016-12-29T01:43:43","guid":{"rendered":"http:\/\/rpchurchill.com\/?p=1272"},"modified":"2017-02-03T13:00:46","modified_gmt":"2017-02-03T18:00:46","slug":"reproducing-a-clever-animation-product-part-28","status":"publish","type":"post","link":"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/12\/28\/reproducing-a-clever-animation-product-part-28\/","title":{"rendered":"Reproducing A Clever Animation Product, Part 28"},"content":{"rendered":"<p>In keeping with this week&#8217;s theme of researching backward compatibility of the various projects I&#8217;ve worked on over the past year I decided to figure out why parts of my fast animation framework weren&#8217;t updating as expected.  The short answer is that IE 11 (and presumably 10 and 9 as well) simply does not process more than one parameter passed to a <code>scale<\/code> command in a <code>style.transform<\/code> assignment.  I originally saw this happen in the debugger using the <code>transform<\/code> property directly.  Changing the code to use <code>msTransform<\/code> (both when hard-coded and when switched after detection) didn&#8217;t change the behavior.<\/p>\n<p>Here&#8217;s the relevant code running in the IE 11 debugger, as it appears just after having executed the statement at line 957.  (<code>transformPrefix<\/code> has the value of &#8220;msTransform&#8221; in this case.)<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.rpchurchill.com\/images\/articles\/20161228_IE_code_steps.png\" style=\"width: 600px;\" \/><\/p>\n<p>&#8230;and here is the value of the variable we have supposedly assigned:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.rpchurchill.com\/images\/articles\/20161228_IE_watch_results\" \/><\/p>\n<p>Doing the same thing in most other browsers results in the watch values taking on the expected result with both parameters.  Although the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/transform\">Mozilla spec<\/a> says that browsers should accept an optional second parameter, IE does not do so.<\/p>\n<p>The solution, therefore,is to test to see if we&#8217;re running IE (9 or later?) and handle this scaling operation with only a single parameter as a special case.  This means we cannot specify different scaling factors in the x- and y-directions but hey, it is what it is and it will do something.  If we really, truly need to scale the axes independently then we can create a mechanism that uses the <code>scaleX<\/code> and <code>scaleY<\/code> commands separately.<\/p>\n<p>I&#8217;ll implement the custom code tomorrow.<\/p>\n<p>I used this code to detect which browser I was using and which prefixes I should use.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      function GetVendorPrefix(arrayOfPrefixes) {\r\n        var tmp = document.createElement(\"div\");\r\n        var result = \"\";\r\n\r\n        for (var i = 0; i < arrayOfPrefixes.length; ++i) {\r\n          var fred = tmp.style[arrayOfPrefixes[i]];\r\n          if ((typeof tmp.style[arrayOfPrefixes[i]] != 'undefined') &#038;&#038; (typeof tmp.style[arrayOfPrefixes[i]] != \"\")) {\r\n           result = arrayOfPrefixes[i];\r\n           break;\r\n          }\r\n          else {\r\n           result = null;\r\n          }\r\n        }\r\n        return result;\r\n      }      \r\n\r\n      var transformPrefix = GetVendorPrefix([\"msTransform\", \"MozTransform\", \"WebkitTransform\", \"OTransform\", \"transform\"]);\r\n      var transitionPrefix = GetVendorPrefix([\"transition\", \"msTransition\", \"MozTransition\", \"WebkitTransition\", \"OTransition\"]);\r\n      var animationPrefix = GetVendorPrefix([\"animation\", \"msAnimation\", \"MozAnimation\", \"WebkitAnimation\", \"OAnimation\"]);\r\n      var gridPrefix = GetVendorPrefix([\"gridRow\", \"msGridRow\", \"MozGridRow\", \"WebkitGridRow\", \"OGridRow\"]);\r\n      var hyphensPrefix = GetVendorPrefix([\"hyphens\", \"msHyphens\", \"MozHyphens\", \"WebkitHyphens\", \"OHyphens\"]);\r\n      var columnPrefix = GetVendorPrefix([\"columnCount\", \"msColumnCount\", \"MozColumnCount\", \"WebkitColumnCount\", \"OColumnCount\"]);\r\n<\/pre>\n<p><code>transformPrefix<\/code> is the only value relevant in this code but I've included the others to demonstrate that they can be used.  The code I lifted from an <a href=\"http:\/\/www.developerdrive.com\/2012\/03\/coding-vendor-prefixes-with-javascript\/\">online example<\/a> (from 2012) didn't test for the typeof result coming back as an empty string; I had to add that when I got that result in the various debuggers when testing the value <code>transform<\/code>.  That used to be first in the list of parameters to the <code>GetVendorPrefix<\/code> call but I moved it to the end to ensure I captured other possible results first.<\/p>\n<p>Once the value of <code>transformPrefix<\/code> is set it can be used in a couple of different ways:<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      \/\/here I'm just building a string that will be executed as a standalone command\r\n      function bcDefineScaleTween(sElement,pStartX,pStartY,pEndX,pEndY,tBegin,tDuration,mMethod) {\r\n        \/\/var s = sElement+\".style.transform='scale(\"+pStartX+\",\"+pStartY+\")';\";\r\n        var s = sElement+\".style.\"+transformPrefix+\"='scale(\"+pStartX+\",\"+pStartY+\")';\";\r\n        ...\r\n\r\n\r\n      \/\/here I'm assigning the property when I can't write the new code out, transformPrefix = \"msTransform\"\r\n      var handle003 = document.getElementById(\"handle003\");\r\n      bcInitElement(handle003,\"120px\",\"60px\",\"yellow\",\"rgba(0,0,0,0)\",\"80px\",0,\"block\",\"This text grows in scale\");\r\n      \/\/ here's where the action is; it works the same way if hard-coded to handle003.style.msTransform \r\n      handle003.style[transformPrefix] = \"scale(0.5,0.5)\";\r\n      addTransformToList(\"handle003\",0.05,{opacity:1.0},\"linear\",\"handle001:2-=0.05\");\r\n      addTransformToList(\"handle003\",1.50,{scale:\"(2.0,2.0)\"},\"linear\",\"+=0.50\");\r\n      addTransformToList(\"handle003\",0.00,{display:\"none\"});\r\n<\/pre>\n<p>It turns out that just using <code>transform<\/code> property in most modern browsers will achieve the desired results.  This must be the outcome of many years of standardization by the vendors.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In keeping with this week&#8217;s theme of researching backward compatibility of the various projects I&#8217;ve worked on over the past year I decided to figure out why parts of my fast animation framework weren&#8217;t updating as expected. The short answer &hellip; <a href=\"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/12\/28\/reproducing-a-clever-animation-product-part-28\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[87,101,49],"_links":{"self":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1272"}],"collection":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1272"}],"version-history":[{"count":13,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1272\/revisions"}],"predecessor-version":[{"id":1403,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1272\/revisions\/1403"}],"wp:attachment":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}