19.02.2010

Before/After Script

Before
After

To emphasize the difference between our raw material and the final results we were using a jQuery plugin called ‘beforeafter’. As the nerds amongst you might have already noticed, we just switched to a more sophisticated solution. The main issue with jQuery.beforeafter is that it is styled with absolute positions, which destroys the whole structure when the user resizes his browser after having loaded the page.

Here is our solution: J&D beforeAfter, entirely scripted in Flash. All you need is the .swf file and the right embedment (which means using swfobject, of course):

<div id="ba_container">
  <script>
    swfobject.embedSWF("beforeafter.swf", "ba_container", "500", "200", "8.0.0", "ba_container", { "before" : "before.jpg", "after" : "after.jpg", "width" : 500, "height" : 200 }, { "allowScriptAccess" : "always" }, { "wmode" : "opaque", "swliveconnect" : true } );
  </script>
</div>

Don’t forget to put the parameters in quotation marks, we’ve talked about that here. Just as jQuery.beforeafter, you can address our script via Javascript and make it show only the before or the after image by calling the function showBefore() and showAfter().

Download the whole source package here and use it for your own comparisons! We didn’t bother documenting the scripts as we built it without the intention of future extension, but the code is not messy at all.

.

Jake & Dan

2 comments

  1. April 2, 2010
    tully said...

    I like the jquery version better. It’s more lightweight and doesn’t require Flash. Also it’s more accessible.

  2. April 3, 2010
    Dan said...

    Hey tully! As mentioned in our post, the jQuery version might be more accessible, but it’s showing SEVERE problems when your design is not based on absolute positions (talking about CSS here). The images will move in a funny way and destroy the whole effect as the user scrolls!

Leave a Reply