title: Zoom out image with CSS3
body: <p>Let's say that I need to make an animation of zooming out the image. This image is set by the user of my site and I don't know its resolution. So, there is a random image on the page and when a visitor clicks on the button it should zoom out the image. JavaScript/jQuery is used <strong>only</strong> in my example to let you know, what's my point, so CSS approach is what I am looking for. Under this text, you can see my code example. When you click on the "toggle" anchor, it should zoom image away.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() {
    $('.toggle').click(function(e) {
      e.preventDefault();
      $('#test').toggleClass('active');
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#test {
    position: relative;
    width: 500px;
    height: 150px;
    overflow: hidden;
  }
  #test img {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: auto;
    transform: translate(-50%, -50%);
    transition: all 5s;
  }
  #test.active img {
    width: auto;
    height: 100%;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="test"&gt;
    &lt;img src="http://www.blueverticalstudio.com/wp-content/uploads/2011/05/1303508174-torre-europa-0180-500x1000.jpg" /&gt;
  &lt;/div&gt;
  &lt;a href="#" class="toggle"&gt;Toggle&lt;/a&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Since this question received a lot of views, I updated my old jsFiddle which I pointed out in the accepted answer as a solution. It is <em>not good</em> and you <strong>should not</strong> use it at all. There is a 99% chance you don't need to use it like that.</p>
  
  <p><a href="https://jsfiddle.net/gej1zb67/" rel="nofollow noreferrer">https://jsfiddle.net/gej1zb67/</a></p>