Book Image

Instant jQuery Masonry How-to

By : Kyle David Taylor
Book Image

Instant jQuery Masonry How-to

By: Kyle David Taylor

Overview of this book

jQuery Masonry is a revolutionary new plugin that enables dynamic layouts on any website. This powerful tool shuffles and rearranges elements to fit any screen size which will ensure your website keeps up with one of the biggest trends of the year, Responsive Web Design.Instant jQuery Masonry How-to will allow you to start building fully responsive layouts for portfolios, galleries, blog pages, and more. Gain a complete understanding of the workings of Masonry, which will allow you to integrate this unique tool into your existing and future projects.The hands-on guide will take you from the basics of jQuery Masonry to utilizing its power within Wordpress and Drupal. You will learn the basics such as implementing single and multi-column layouts, before developing more complex solutions for various media types, fluid layouts, and animating transitions. With the widespread adoption of responsive web design, this book will bring your blog, portfolio, or any project you are working on up to speed.
Table of Contents (7 chapters)

Preface

jQuery Masonry is a dynamic grid layout plugin. Masonry works by identifying the space needed by elements in a specific container on a web page and arranges them in an efficient manner that maximizes the use of the area given.

What this book covers

Setting up a single-width column system (Simple) shows you how to set up the very basic Masonry single-width column system around which Masonry revolves.

Setting up a multi-width column system (Simple) shows how Masonry allows us to define a set of multiple widths in CSS so elements can span across multiple columns.

Using Masonry with images (Intermediate) talks about how we can properly use images in conjunction with Masonry. Because Masonry depends on using the height and width of an element, we need to account for that.

Adding media for multi-width columns (Intermediate) shows how we can handle instances where we need to account for the addition of multiple types of media, such as videos and images; this is considering the fact that multi-width columns give a great look to blog rolls and news feeds.

Using fluid layouts (Intermediate) goes over how to set the column widths to use fluid layout instead of responsive layout when building sites for mobile interfaces.

Animating using jQuery (Intermediate) shows how we can have a little fun using animations, which comes shipped with Masonry, when resizing the container area.

Animating using CSS3 (Intermediate) goes over how we use CSS3 animations and Modernizr to help us fall back to jQuery.

Integrating with WordPress (Advanced) goes over how we can integrate Masonry with the popular WordPress CMS, owing to the rising popularity of using content management systems.

Integrating with Drupal (Advanced) goes over the modules and integration process of Masonry with Drupal, which is the next most popular used content management system.

Adding and reloading (Advanced) goes over using Masonry's append and reload methods to align newly added content into the existing grid. This recipe is helpful for situations where we work on specialized projects that might involve dynamically adding content to a web page.

Placing a corner stamp (Advanced) shows how to implement a corner stamp in our Masonry grid. This would be helpful because Masonry moves content around when the container has different widths, and sometimes we want to keep a specific element at the top at all times, such as an author bio or featured product.

Aligning items from right to left (Advanced) shows us how to use the built-in Right-To-Left support within Masonry because in some instances when using Middle Eastern or Hebrew languages, the text needs to be aligned from right to left.

What you need for this book

For this book, you will need a text editor or IDE, an up-to-date browser such as Google Chrome or Mozilla Firefox, and a copy of the jQuery Masonry plugin. We will be using a CDN in some cases, such as the base jQuery library.

Who this book is for

If you have a basic understanding of jQuery, HTML, and CSS3, this book is for you. It is recommended that you have some prior experience working with JavaScript and/or jQuery. If you are used to working with JavaScript and want to learn a new jQuery plugin that can add a beautiful, clean grid layout to your site, you will find this book a breeze to read.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Using jQuery, we select our Masonry container and use the itemSelector option to select the elements that will be affected by Masonry."

A block of code is set as follows:

<style>
   .masonry-item {
      background: #FFA500;
      direction: rtl;
      float: left;
      margin: 5px;
      padding: 5px;
      width: 130px;
   }
</style>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<script>
  $(function() {
    $('#masonry-container').masonry({
      itemSelector: '.masonry-item',
      columnWidth : function(containerWidth) {
        return containerWidth / 4;
      }
    });
  });
</script>

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.