JQuery Masonry waterfall stream plug-in usage details, jquerymasonry

Source: Internet
Author: User

JQuery Masonry waterfall stream plug-in usage details, jquerymasonry

Masonry is a powerful jQuery dynamic grid layout plug-in that can help developers quickly develop interface effects similar to clip art. The effect of float in CSS is not the same as that of float. float is first horizontally arranged and then vertically arranged. With Masonry, elements are vertically arranged, then place the next element in the next development area of the grid. This effect minimizes the gap between elements of different heights in the vertical direction. As follows:

As you can see in the figure, using float to process elements of different heights in the grid layout makes the interval between elements in the vertical direction relatively large. After using Masonry to process elements, the interval decreases.

Usage

First, import the class library as follows:

Copy codeThe Code is as follows:
<Script src = "// ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js">
</Script> <script src = "/path/to/jquery. masonry. min. js"> </script>

Then, execute masonry for the element container as follows:

Copy codeThe Code is as follows:
$ (Function (){
$ ('# Iner'). masonry ({
// Options
ItemSelector: '. item ',
ColumnWidth: 240
});
});

Html code

Copy codeThe Code is as follows:
<Div id = "container">
<Div class = "item">... </div>
<Div class = "item">... </div>
<Div class = "item">... </div>
...
</Div>

Css

Copy codeThe Code is as follows:
. Item {
Width: 220px;
Margin: 10px;
Float: left;
}

If there are images in the loaded elements, make sure that Masonry is executed after all the images are loaded. You need to call the following code:

Copy codeThe Code is as follows:
Var $ container = $ ('# iner ');
$ Container. imagesLoaded (function (){
$ Container. masonry ({
ItemSelector: '. item ',
ColumnWidth: 240

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.