/components/jquery-masonry/_posts/docs/2011-05-04-animating.mdown

https://bitbucket.org/ceoaliongroo/torredelprior · Unknown · 93 lines · 66 code · 27 blank · 0 comment · 0 complexity · 8dad9d50c0b68aa50c6075a8e6796653 MD5 · raw file

  1. ---
  2. title: Animating
  3. category: docs
  4. layout: default
  5. toc:
  6. - { title: jQuery, anchor: jquery }
  7. - { title: CSS transitions, anchor: css_transitions }
  8. - { title: Modernizr, anchor: modernizr }
  9. ---
  10. Rearrangements can be animated when the container is resized.
  11. ## jQuery
  12. To animate Masonry layout changes with jQuery, set the `isAnimated` option to `true`.
  13. {% highlight javascript %}
  14. $('#container').masonry({
  15. // options...
  16. isAnimated: true
  17. });
  18. {% endhighlight %}
  19. [See Demo: Animating with jQuery](../demos/animating-jquery.html).
  20. You can pass in jQuery animation options are set with the [`animationOptions` option](options.html#animationoptions).
  21. {% highlight javascript %}
  22. $('#container').masonry({
  23. // options...
  24. isAnimated: true,
  25. animationOptions: {
  26. duration: 750,
  27. easing: 'linear',
  28. queue: false
  29. }
  30. });
  31. {% endhighlight %}
  32. ## CSS transitions
  33. Alternatively, you can rely on CSS3 transitions to animate layout rearrangements. Enabling transitions is recommended, as they provide for better browser performance over jQuery animation.
  34. In your CSS, add transition styles below. The Masonry plugin will add a class of `masonry` to the container after the first arrangement so transitions can be applied afterward. Item elements will have a class of `masonry-brick` added.
  35. [See Demo: Animating with CSS transitions](../demos/animating-css-transitions.html).
  36. {% highlight css %}
  37. /**** Transitions ****/
  38. .masonry,
  39. .masonry .masonry-brick {
  40. -webkit-transition-duration: 0.7s;
  41. -moz-transition-duration: 0.7s;
  42. -o-transition-duration: 0.7s;
  43. transition-duration: 0.7s;
  44. }
  45. .masonry {
  46. -webkit-transition-property: height, width;
  47. -moz-transition-property: height, width;
  48. -o-transition-property: height, width;
  49. transition-property: height, width;
  50. }
  51. .masonry .masonry-brick {
  52. -webkit-transition-property: left, right, top;
  53. -moz-transition-property: left, right, top;
  54. -o-transition-property: left, right, top;
  55. transition-property: left, right, top;
  56. }
  57. {% endhighlight %}
  58. ## Modernizr
  59. To get the best of both worlds, you can use [Modernizr](http://www.modernizr.com/) to detect browser support for CSS transitions. Add the transitions styles above, then enable `animated` based on Modernizr's detected support for transitions. This will allow browsers that support CSS transitions to use them, and browsers without support to use jQuery animation.
  60. [See Demo: Animating with Modernizr](../demos/animating-modernizr.html).
  61. {% highlight javascript %}
  62. $('#container').masonry({
  63. // options...
  64. isAnimated: !Modernizr.csstransitions
  65. });
  66. {% endhighlight %}