Giter VIP home page Giter VIP logo

blocksit.js's Introduction

#blocksit.js

BlocksIt.js is a jQuery plugin for creating dynamic grid layout. It manages to convert HTML elements into ‘blocks‘ and position them in well-arranged grid layout like Pinterest, one of the hottest website nowadays =). How? Well, simply specific the number of columns you wish to have and BlocksIt.js will do the rest for you. Also, you can even combine the ‘blocks‘ and make a huge block! So, let’s blocks it!

#How It Works

BlocksIt.js will re-position the selected elements using CSS absolute position property. It has the capability to calculate the top and left positions for an element based on certain criteria, like below:

  1. Start the new block from left to right, and
  2. Place the new block under shortest block.

#How to use

  1. First, include jQuery and BlocksIt.js script files inside the <head> tag like usual.
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="blocksit.js"></script>

It should works well with jQuery 1.7.1 (haven’t tested for lower version).

  1. Next, call the .BlocksIt() function on jQuery object.
$(document).ready(function() {
   $('#objectID').BlocksIt();
});
  1. Done! =)

Note: If the blocks contains of element, be sure to specific the images’ height before calling .BlocksIt() function, else you have to make sure the images are loaded.You could use $(window).load() to make sure everything have loaded into DOM, or use some plugin like waitForImages to check the images status.

#Configuration

//.BlocksIt( [Options] )
$('.container').BlocksIt({
            numOfCol: 5,
            offsetX: 5,
            offsetY: 5,
            adjustWidth: false,
            blockElement: 'div'
});
Name Type Default Description
numOfCol Int 5 The number of columns to be created.
offsetX Int 5 Margin left and right for each block.
offsetY Int 5 Margin top and bottom for each block.
adjustWidth Boolean false If true, blocksit will resize the child elements width
blockElement String "div" Targeted child elements, which will be converted into blocks.

#FAQ

1. My elements are set outside of my container! Why?

I don't know why, but to fix it, make sure your container has the following css property: position: relative;

2. Can I see what it does ?

There is actually two example available. First, Second.

#About this git

This git repository is here to help improve the original script file originally found on inwebson. Pull requests, submit issues, whatever helps!

blocksit.js's People

Stargazers

kevin avatar  avatar Mickaël CASSY avatar

Watchers

James Cloos avatar Eunsik Lyang avatar Mickaël CASSY avatar  avatar

blocksit.js's Issues

IE window/screen size <1100px

Instead of defining number of columns on load, it should find out the window size and assign the layout accordingly. A modification of your window.resize function can be used:

$(window).load( function() {
var winWidth = $(window).width();
var conWidth;
if(winWidth < 660) {
conWidth = 440;
col = 2
} else if(winWidth < 880) {
conWidth = 660;
col = 3
} else if(winWidth < 1100) {
conWidth = 880;
col = 4;
} else {
conWidth = 1100;
col = 5;
}
$('#container').width(conWidth);
$('#container').BlocksIt({
numOfCol: col,
offsetX: 8,
offsetY: 8
});
});

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.