Coder Social home page Coder Social logo

danielpaz6 / waterfall.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raphamorim/waterfall.js

1.0 0.0 0.0 111 KB

Tired of use creepy hacks or heavy ways to get a Grid based on Pinterest?

Home Page: http://raphamorim.io/waterfall.js/

JavaScript 100.00%

waterfall.js's Introduction

Build Status NPM Version Standard - JavaScript Style Guide

Waterfall.js

Tired of using creepy hacks or heavy ways to get a grid based on Pinterest?

1KB and works without any dependency, also UMD support available too \o/

The "Why"

Currently the best option today to do this job is Masonry, but it's very heavy and has a jQuery dependency. Please understand: this isn't a problem in most cases, but when perfomance and page weight matters, it's best to try other options: maybe pure CSS? Is it possible?

This question has a good point. Yes, there are CSS ways to solve this, using flexbox or columns technic, but this doesn't work well when you don't know about your data/structure. So we have to use JavaScript. The challenge is create a decent algorithm where the structure doesn't matter: Waterfall will work.

However; Waterfall always will consider items with same width :)

How to Use?

Getting

First at all, get Waterfall using Download Option

Get it using npm or yarn by running this command

npm install [email protected]

or

⚠️ The latest stable is waterfall-1.0.2 (which is used in the website), newest versions are suffering issues from a major rewrite.

You can import

import waterfall from 'waterfall.js/src/waterfall'

Or add the source before the closing body tag:

<script src="waterfall.min.js"></script>
</body>

Another option: Waterfall.js is currently available in cdnjs, so you can use it from there too.

<script src="//cdnjs.cloudflare.com/ajax/libs/waterfall.js/1.0.2/waterfall.min.js"></script>
</body>

Usage

Define your grid structure:

<div class="grid">
    <div class="item">Solid Snake</div>
    <div class="item">Riou</div>
    <div class="item">Jack Russel</div>
</div>

Call Waterfall function with your grid as a argument and let the magic happen :)

waterfall('.grid');
// or
var grid = document.querySelector('.grid');
waterfall(grid);

Responsive

Just call Waterfall function again on window resize event:

window.addEventListener('resize', function () {
    waterfall(grid);
});

Many images to load

In this case we highly recommend you run the waterfall only after the images have been loaded. Because Waterfall.js requires information about height / width of the images.

A quick solution is to use imgStatus (no dependencies and only 855bytes) to check the images were loaded.

Browser Support

Chrome logo Firefox logo Internet Explorer logo Opera logo Safari logo
42+ ✔ 40+ ✔ 8+ ✔ 29+ ✔ 8+ ✔

Credits

A special thanks to @israelst and @eduardostalinho.

License

The MIT License (MIT)

Copyright (c) 2015 Raphael Amorim

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

waterfall.js's People

Contributors

raphamorim avatar israelst avatar pedropolisenso avatar diegohaz avatar thiamsantos avatar felquis avatar dirkk0 avatar peterdavehello avatar ronalson avatar sculove avatar afonsopacifer avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.