Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 326 lines (238 sloc) 17.028 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery Masonry &rsaquo; Primer</title>

<link rel="stylesheet" href="css/masonry-example.css" media="screen" />

<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery.masonry.js"></script>
    <script type="text/javascript">
     $(function(){
     $('#secondary').masonry({columnWidth: 100});
     })
    </script>
    

</head>
<body>

    <ol id="nav" class="nav">
        <li><strong>jQuery Masonry &rsaquo;</strong></li>
        <li class="selected"><a href=".">Primer</a></li>
        <li><a href="basic.html">Basic Examples</a></li>
        <li><a href="tumblelog.html">Tumblelog</a></li>
        <li><a href="infinite-scroll.html">Infinite Scroll</a></li>
        <li><a href="animated.html">Animated</a></li>
        <li><a href="filtering.html">Filtering</a></li>
    </ol>

<h1>Primer</h1>

    <div class="copy">
        <p>Masonry is a layout plugin for jQuery. Think of it as the flip side of CSS floats. Whereas floating arranges elements horizontally then vertically, Masonry arranges elements vertically then horizontally according to a grid. The result minimizes vertical gaps between elements of varying height, just like a mason fitting stones in a wall.</p>
        
    </div><!-- .copy -->

    <div id="comparison">
        <h2>Comparison Example</h2>
        <div class="example">
            <h3>CSS Floats</h3>
            <div id="primary" class="wrap">
                <div class="box col1">
                    <h5>1</h5>
                    <p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris. </p>
                </div>

                <div class="box col2">
                    <h5>2</h5>
                    <p>Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit.</p>
                </div>

                <div class="box col1">
                    <h5>3</h5>
                    <p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula. Ut eget sem risus, et posuere velit. Aenean ac mauris non ligula. </p>
                </div>

                <div class="box col1">
                    <h5>4</h5>
                    <p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus.</p>
                </div>

                <div class="box col1">
                    <h5>5</h5>
                    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.</p>
                </div>

                <div class="box col1">
                    <h5>6</h5>
                    <p>Cadipiscing in, lacinia vel, tellus. </p>
                </div>

                <div class="box col1">
                    <h5>7</h5>
                    <p>Pellentesque a diam sit amet mi ullamcorper vehicula. adipiscing in, lacinia vel, tellus.</p>
                </div>
                
                <div class="box col3">
                    <h5>8</h5>
                    <p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Suspendisse ac urna. Etiam pellentesque. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl. Suspendisse ac urna. Etiam pellentesque. </p>
                </div>

                <div class="box col2">
                    <h5>9</h5>
                    <p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue. Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Pellentesque a diam sit amet mi ullamcorper vehicula. adipiscing in, lacinia vel, tellus.</p>
                </div>

                <div class="box col1">
                     <h5>10</h5>
                     <p>Etiam pellen tesque mauris ut lectus.</p>
                 </div>

                 <div class="box col1">
                     <h5>11</h5>
                     <p>Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspen disse ac urna. Ut condi mentum mi vel tellus.</p>
                 </div>

                 <div class="box col1">
                      <h5>12</h5>
                     <p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
                 </div>

            </div> <!-- /#primary.wrap -->
        </div>

        <div class="example">
            <h3>Masonry</h3>
            <div id="secondary" class="wrap">
                <div class="box col1">
                    <h5>1</h5>
                    <p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris. </p>
                </div>

                <div class="box col2">
                    <h5>2</h5>
                    <p>Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit.</p>
                </div>

                <div class="box col1">
                    <h5>3</h5>
                    <p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula. Ut eget sem risus, et posuere velit. Aenean ac mauris non ligula. </p>
                </div>

                <div class="box col1">
                    <h5>4</h5>
                    <p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus.</p>
                </div>

                <div class="box col1">
                    <h5>5</h5>
                    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.</p>
                </div>

                <div class="box col1">
                    <h5>6</h5>
                    <p>Cadipiscing in, lacinia vel, tellus. </p>
                </div>

                <div class="box col1">
                    <h5>7</h5>
                    <p>Pellentesque a diam sit amet mi ullamcorper vehicula. adipiscing in, lacinia vel, tellus.</p>
                </div>
                
                <div class="box col3">
                    <h5>8</h5>
                    <p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Suspendisse ac urna. Etiam pellentesque. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl. Suspendisse ac urna. Etiam pellentesque. </p>
                </div>

                <div class="box col2">
                    <h5>9</h5>
                    <p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue. Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Pellentesque a diam sit amet mi ullamcorper vehicula. adipiscing in, lacinia vel, tellus.</p>
                </div>

                <div class="box col1">
                     <h5>10</h5>
                     <p>Etiam pellen tesque mauris ut lectus.</p>
                 </div>

                 <div class="box col1">
                     <h5>11</h5>
                     <p>Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspen disse ac urna. Ut condi mentum mi vel tellus.</p>
                 </div>

                 <div class="box col1">
                      <h5>12</h5>
                     <p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
                 </div>

            </div> <!-- /#secondary.wrap -->
        </div>

    </div>



<div class="copy">

        <h2 id="min-config">Minimum recommended configuration</h2>

        <p>Configuring Masonry is fairly easy. Simply attach the <code>.masonry()</code> method to the wrapping container element. Depending on the layout, you&rsquo;ll most likely need to specify one option.</p>

        <p>For layouts with elements that span multiple widths:</p>

        <pre><code><span class="keyword">$</span>(<span class="string">'#wrapper'</span>).masonry({ columnWidth: <span class="constant">200</span> });</code></pre>

        <p>For layouts with elements that span the same width:</p>

        <pre><code><span class="keyword">$</span>(<span class="string">'#wrapper'</span>).masonry({ singleMode: <span class="constant">true</span> });</code></pre>


        <h2 id="options">All options</h2>

<pre><code><span class="keyword">$</span>(<span class="string">'#wrapper'</span>).masonry({

    singleMode: <span class="constant">false</span>,
    <span class="comment">// Disables measuring the width of each floated element.
    // Set to true if floated elements have the same width.
    // default: false</span>

    columnWidth: <span class="constant">240</span>,
    <span class="comment">// Width in pixels of 1 column of your grid.
    // default: outer width of the first floated element.</span>

    itemSelector: <span class="string">'.box:visible'</span>,
    <span class="comment">// Additional selector to specify which elements inside
    // the wrapping element will be rearranged.
    // Required for Infinite Scroll with window resizing.</span>

    resizeable: <span class="constant">true</span>,
    <span class="comment">// Binds a Masonry call to window resizes
    // so layout appears fluid.
    // default: true</span>

    animate: <span class="constant">true</span>,
    <span class="comment">// Animates layout rearrangements.
    // default: false</span>

    animationOptions: {},
    <span class="comment">// A map of options for animation.</span>

    appendedContent: <span class="keyword">$</span>(<span class="string">'.new_content'</span>),
    <span class="comment">// Additional container element for appended content.
    // Useful for Infinite Scroll integration.</span>

    saveOptions: <span class="constant">true</span>,
    <span class="comment">// Masonry will use the options from previous Masonry
    // calls by default, so you only have to enter in options once
    // default: true</span>

}, <span class="storage">function</span>() {}
    <span class="comment">// Optional callback.
    // 'this' will refer to the applicable elements Masonry just rearranged</span>

);</code></pre>

        <p>No need to worry about how many columns, or width of gutters, or how big the container is. Thanks to the wonders of jQuery’s <code>outerWidth()</code> and <code>innerWidth()</code> methods, Masonry appropriately accounts for the space of any margin, padding, and border-width set with CSS. </p>

        <h2 id="project-home">Project Home</h2>
        
        <p>This project lives on GitHub at <a href="http://github.com/desandro/masonry">github.com/desandro/masonry</a>, where you can follow progress and download all these demos and documentation, and grab the latest version of the script.</p>
        
        <p>There you can find an <a href="http://github.com/desandro/masonry/issues">issue tracker</a> where you can look through other people's <a href="http://github.com/desandro/masonry/issues/closed">resolved issues</a> or submit a new one for yourself. If you're still having trouble, try <a href="http://wiki.github.com/desandro/masonry/">looking over the FAQ</a>.</p>
        
        <h2 id="resizing">Window Resizing</h2>
        
        <p>By default, Masonry binds a call to the browser window for resizing. But the rearrangement script is triggered only when the layout adds or loses a column, so you don&rsquo;t have to worry about Masonry slowing down window resizes, or with fixed layouts.</p>

        <h2 id="images">Handling Images &amp; Other Media</h2>

        <p>Since Masonry measures the height of the elements when placing them, you will need to account for images and other media that haven&rsquo;t loaded yet. For images, the best method is to specify the width and height of images inline.</p>

        <pre><code><span class="storage">&lt;img src=<span class="string">"img_file.jpg"</span> <span class="string">width="280"</span> <span class="string">height="160"</span> /&gt;</span></code></pre>

        <p>If you&rsquo;re using a PHP-based CMS, you can use the <a href="http://php.net/manual/en/function.getimagesize.php">getimagesize</a> function.</p>

        <p>If this is not possible or if you&rsquo;re dealing with @font-face fonts, another option is to call Masonry after all media has loaded. This is done by calling the function inside of <code>$(window).load()</code> instead of <code>$(document).ready()</code>.</p>

        <pre><code><span class="keyword">$</span>(<span class="support">window</span>).<span class="keyword">load</span>(<span class="storage">function</span>(){
    <span class="keyword">$</span>(<span class="string">'#wrapper'</span>).masonry({ columnWidth: <span class="constant">200</span> });
});</code></pre>

        <h2 id="anchor-links">Resolving Anchor Links</h2>

        <p>Since Masonry relies on absolute positioning, any anchor links that occur within or after the wrapping element will not work when the page first loads. The following script is one solution.</p>

        <pre><code><span class="keyword">$</span>(<span class="support">window</span>).<span class="keyword">load</span>(<span class="storage">function</span>(){
    <span class="keyword">if</span> ( <span class="keyword">window</span>.<span class="keyword">location</span>.<span class="keyword">hash</span> ) {
        <span class="storage">var</span> destination = <span class="keyword">$</span>( <span class="keyword">window</span>.<span class="keyword">location</span>.<span class="keyword">hash</span> ).offset().<span class="keyword">top</span>;
        <span class="keyword">$</span>(<span class="string">'html:not(:animated),body:not(:animated)'</span>).scrollTop( destination );
    }
});</code></pre>

        <p>This will set the window of the document to the appropriate place. These couple lines were taken from <a href="http://www.position-absolute.com/articles/better-html-anchor-a-jquery-script-to-slide-the-scrollbar/">Cedric Dugas’s anchorAnything.</a></p>

        <h2 id="inthewild">Examples in the Wild</h2>

        <p>In addition to the examples below, see <a href="http://delicious.com/desandro/jquerymasonry">delicious links tagged with jquerymasonry</a> and <a href="http://emberapp.com/desandro/collections/jquery-masonry">jQuery Masonry Collection on Ember for screenshots</a>.</p>
        
        <ul>

            <li><a href="http://bygonebureau.com/">The Bygone Bureau</a></li>
            <li><a href="http://thoughtandtheory.com/collection/">Thought &amp; Theory - Collection</a></li>
            <li><a href="http://safe.tumblr.com/theme/preview/8951">Scaffold Tumblr Theme by Mike Harding</a></li>
            <li><a href="http://alpha.patterntap.com">Pattern Tap</a></li>
            <li><a href="http://www.puma.com/running/media">PUMA Running | Media</a></li>
            <li><a href="http://veerle.duoh.com/inspiration">The Inspiration Stream | Veerle's blog 3.0</a></li>
            <li><a href="http://thomasmatthews.com/index.php/portfolio/print/">thomas.matthews</a></li>
            <li><a href="http://rathersplendid.net/">Rather Splendid</a></li>
            <li><a href="http://chromeography.com">Chromeography</a></li>
        </ul>
        
        <h2 id="changelog">Changelog</h2>

        <dl>
            <dt>v1.2 12 Jun 2010</dt>
            <dd>Support for filtering added</dd>
            <dd>Full animation options added</dd>
            <dt>v1.1: 29 Apr 2010</dt>
            <dd>Add animation</dd>
            <dt>v1.0: 7 Dec 2009</dt>
            <dd>Multi-column width support</dd>
            <dd>Appending elements and Infinite Scroll support</dd>
            <dd>Less obstrusive layout. No inserting additional markup.</dd>
            <dd>Automatically binds event to window resizing</dd>

            <dt>v0.4: 14 Jun 2009</dt>
            <dd>Better fluid rearrangement support</dd>

            <dt>v0.1: Feb 2009</dt>
            <dd>Original release</dd>
        </dl>

        <h2 id="license">License</h2>
        
        <p>jQuery Masonry is dual-licensed under <a href="http://www.gnu.org/licenses/gpl.html">GPL</a> and <a href="http://en.wikipedia.org/wiki/MIT_License">MIT</a>, just like <a href="http://docs.jquery.com/License">jQuery itself.</a> You can use it for both personal and commercial applications.</p>

</div>


<p id="footer">

jQuery Masonry by <a href="http://desandro.com/">David DeSandro</a>
</p>

</body>
</html>
Something went wrong with that request. Please try again.