<?xml version="1.0" encoding="UTF-8"?> 
<rss version="2.0"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:atom="http://www.w3.org/2005/Atom"
        xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
        >
<channel>
  <title>asgaard</title>
  <description></description>
  <link>https://blog.asgaard.co.uk/2012/07/09/knockoutjs-and-css-transitions</link>
  <lastBuildDate>Tue, 05 May 26 16:44:15 +0000</lastBuildDate>
  <language>en</language>
  <count>1</count>
  <offset>0</offset>
      <item>
    <title>KnockoutJS and CSS transitions</title>
    <link>https://blog.asgaard.co.uk/2012/07/09/knockoutjs-and-css-transitions</link>
    <pubDate>Mon, 09 Jul 12 15:24:55 +0000</pubDate>
    <guid>https://blog.asgaard.co.uk/2012/07/09/knockoutjs-and-css-transitions</guid>
    <description><![CDATA[
<p>
Something I&#039;ve noticed with KnockoutJS is that sometimes CSS transitions don&#039;t seem to work properly when adding/removing classes from DOM elements with the <code>css</code> binding. 
<p>
After some investigation, it turns out that Knockout will often re-render the template when such a binding is fired, meaning that you effectively get a new DOM node with the class set (or not set), so the transition doesn&#039;t fire. You can use the <code>afterRender</code> callback to find out when the template is re-rendered.
<p>
I haven&#039;t worked out exactly what circumstances trigger the re-rendering; some situations are fine. I came across it in something I&#039;m writing now and tried to get a simple test case together to submit a bug report, and I just couldn&#039;t reproduce it. And of course the situation I had was far too complex to submit. I don&#039;t think it&#039;s the CSS binding itself that causes it - I wrote a custom dummy binding that didn&#039;t do anything (literally just a return statement) and merely having that bind[...]]]></description>
    <content:encoded><![CDATA[
<p>
Something I&#039;ve noticed with KnockoutJS is that sometimes CSS transitions don&#039;t seem to work properly when adding/removing classes from DOM elements with the <code>css</code> binding. 
<p>
After some investigation, it turns out that Knockout will often re-render the template when such a binding is fired, meaning that you effectively get a new DOM node with the class set (or not set), so the transition doesn&#039;t fire. You can use the <code>afterRender</code> callback to find out when the template is re-rendered.
<p>
I haven&#039;t worked out exactly what circumstances trigger the re-rendering; some situations are fine. I came across it in something I&#039;m writing now and tried to get a simple test case together to submit a bug report, and I just couldn&#039;t reproduce it. And of course the situation I had was far too complex to submit. I don&#039;t think it&#039;s the CSS binding itself that causes it - I wrote a custom dummy binding that didn&#039;t do anything (literally just a return statement) and merely having that binding set was enough to cause the problem.
<p>
So far I&#039;ve not found a better workaround than avoiding the the binding and using jQuery (or pure JS) to set the classname, but this is only practical in specific circumstances: it can be hard to associate DOM elements with these workarounds and get them to fire at the right time. Obviously you could also use knockout&#039;s events to handle the animation in pure jQuery, but with CSS transitions widely supported now and browsers supporting offloading instructions to the GPU, it seems untidy, no scratch that, _just plain wrong_, to force animation onto the JS interpreter.]]></content:encoded>
  </item>
  </channel>
</rss>