Giter Club home page Giter Club logo

jquery.mosaicflow's Introduction

Mosaic Flow

Powered by You Build Status Bower version CDNJS

Pinterest like responsive image or HTML grid for jQuery that doesn’t suck. See live example.

Features

  • Simple and easy to install.
  • Responsive (shows as many columns as needed).
  • Very fast.
  • Only 1.5 KB (minified gzipped).
  • You can use bare <img> tags or arbitrary HTML.

Installation

Include jQuery and jquery.mosaicflow.min.js onto your page:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="jquery.mosaicflow.min.js"></script>

Add some CSS for column layout and to make your content responsive:

.mosaicflow__column {
  float: left;
}
.mosaicflow__item img {
  display: block;
  width: 100%;
  height: auto;
}

Add .mosaicflow CSS class to your content’s contaier:

<div class="clearfix mosaicflow">
  <div class="mosaicflow__item">
    <img src="1.jpg" width="500" height="300" alt="">
  </div>
  <div class="mosaicflow__item">
    <img src="2.jpg" width="500" height="500" alt="">
  </div></div>

Image sizes should be specified in HTML in conjunction with option itemHeightCalculation = 'attribute' for even a better performance.

You can also use custom HTML as items:

<div class="clearfix mosaicflow">
  <div class="mosaicflow__item">
    <h4>Lorem ipsum dolor sit amet</h4>
    <p>Excepteur sint occaecat cupidatat non proident</p>
  </div>
  <div class="mosaicflow__item">
    <h4>Lorem ipsum dolor sit amet</h4>
    <p>Excepteur sint occaecat cupidatat non proident</p>
  </div></div>

Configuration and manual initialization

You can define options via HTML data attributes or via JavaScript object (manual initialization).

<div class="clearfix mosaicflow" data-item-selector=".item" data-min-item-width="300">
$('#mycontainer').mosaicflow({
  itemSelector: '.item',
  minItemWidth: 300
});

Don’t add .mosaicflow class when you manually initialize Mosaic Flow—it will ignore options specified through Javascript.

Note that option names in JavaScript should be in camelCase but in HTML it should be data-attributes-with-dashes.

Options

itemSelector (default: > *)

jQuery selector of content item.

columnClass (default: mosaicflow__column)

CSS class of column element.

minColumns (default: 2)

Minimum number of columns. Especially useful for mobile devices.

minItemWidth (default: 240)

Minimum item (or column) width. Decrease this number if you want more columns, or increase if you want less.

itemHeightCalculation (default: auto)

Method of calculation items’ heights:

  • auto—will calculate automatically each item’s height after being placed in a column, so it is smart enough if your items are responsive and height is being modified as width is (which will happen as columns shrink or expand).

  • attribute—will try to grab the value placed in height attribute of <img> tags when these are used as items. This is faster than auto because no calculation is done.

Events

mosaicflow-layout

Fire on every layout change: initialization or change number of columns after window resize.

mosaicflow-start / mosaicflow-ready

Fire before / after the mosaicflow init it's work.

mosaicflow-fill / mosaicflow-filled

Fire before / after reorganized columns.

mosaicflow-item-add / mosaicflow-item-added

Fire before / after adding items.

mosaicflow-item-remove / mosaicflow-item-removed

Fire before / after removing items.

Methods

add

Add any html element into next smallest column.

Example:

// Init mosaicflow
var container = $('#mycontainer').mosaicflow();

// Create new html node and append to smallest column
var elm = $('<div>A new added element</div>');
container.mosaicflow('add', elm);

remove

Remove a given element from its column and updates columns height accordingly. It does not removes the node, just detaches it from document. Example:

// Init mosaicflow
var container = $('#mycontainer').mosaicflow();

// Select the desired element to be removed
var elm = $('#item-3');

// Tell mosaicflow to detach element from its column
container.mosaicflow('remove', elm);

// Now you can place detached node in another location or remove it if you don't need it anymore.
elm.remove();

Release History

The changelog can be found in the Changelog.md file.


License

The MIT License, see the included License.md file.

jquery.mosaicflow's People

Contributors

jdmeer avatar kdzuin avatar mvavrecan avatar phildittrich avatar sapegin avatar sija avatar starefossen avatar sufuf3 avatar sunify avatar vitos555 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.mosaicflow's Issues

Jumping from 4 columns to 2 columns

When My containing Div shrinks from over 700px to less than 700px it jumps from being 4 columns directly to 2 columns and vice versa...
only during slow resizing 3 columns appear... sometimes... and just for a few px, than it goes back to the even columns.

Basically anything is on default
<div class="clearfix mosaicflow" data-item-selector=".mosaicflow__item" data-min-item-width="240" data-min-columns="2" itemHeightCalculation="auto"> <div class="mosaicflow__item"> <img src="http://exh5266.cias.rit.edu/256/homework3/images/kitten.jpg" width="240" height="auto" alt=""> </div> ...

There is also no other css than the basic affecting these elements...

So yeah, what could be the reason for that and is it possible to manually set the re-align width?

Work with different width

I set the "minItemWidth" to 500. So all my columns got the same width. How can i work with different column widths?

Column spanning

Do you have any ideas on how elements spanning multiple columns could be integrated into Mosaicflow? Looking at the source, I doubt an element could break out of one of the columns as they currently stand.

Columns would need to have a certain ratio, in which elements would be ( N * span) * ( 100 / colSpan ) wide. Or something. Its' late.

I'd love to hear your thoughts.

p tag styling

I noticed that the basic CSS given on your homepage for the plugin does not include the styling for the p tag, however, it sits directly below an example of the plugin where the p tag is clearly styled as intended.

I noticed on the files I downloaded from you yesterday, the example included, had some styles for the p tag included in the head section, could these be included on the home page that includes the basic css to make it work?

Best

Graeme

P.s. new to all this so learning and trying to contribute positively.

Use ES6 module

Hi @sapegin,

I would like to discuss with you if you were interested for a migration to use ES6 module on this project. I know that this project is not actively maintain, but I would be happy to work on it and to send you a PR for that. I think this migration could be great as we will be able to use the library with an ES6 bundler (rollup or webpack) without any plugins.

What do you think?

2 columns for mobile size

Is it possible to display two columns instead of one for devices less/approx than 400 (mobile device)?
Instead of showing one as its not really a mosaic style for mobile users otherwise :)

Thanks

Initializing with no columns

No columns are initialised on page load, and are only created when window resize event is triggered, producing a single column initially. Any ideas?

Thanks

Specifying Gutters Between Columns

What's the best way to do this? I was having a play with CSS, but it seems like the widths are all set to fill the container and not allow for gutters.

      $(window).bind("mosaicflow-layout", function(e){
        var index = $('.mosaicflow__column').length - 1;
        $(".mosaicflow__column").eq(index).css({marginRight: 0});
      });

Image size while loading

The first image in the mosaic flow gets the full width for a fraction of a second while loading for the first time .How to fix it sir ?

add item return jquery error

on firefox 29.0.1 based on the exemple in /specs/html.html creating mosaicflow instance works fine but addin element trow a jquery error see below

// works fine
$('#mycontainer').mosaicflow({
itemSelector:'.item',
minItemWidth: 300
});

// add item : new and old method return error : TypeError: e is undefined ...){var t=e.nodeName.toLowerCase()return"input"===t&&"button"===e.type||"button"=...jquery.min.js (ligne 4)
var container = $('#mycontainer').mosaicflow();
// Create new html node and append to smallest column
var elm = $('element inside div from exemple');
container.mosaicflow('add', elm);

Feature request: reflow method

I need different minItemWidth for different window widths, so at initialisation I use this:

minItemWidth: ($(window).width() < 1600) ? 341 : 450

And it works fine

Until I resize window, so I need to update minItemWidth option and to reflow mosaicflow, which will update mosaic layout with updated minItemWidth value.

Images are invisible until I manually resize the browser window

When I use mosaicflow "regularly", that is, with pre-loaded images, with mosaic-flow being called within a $(document).ready() type structure, everything works just fine.

But in my site I'm doing this differently. The images are preloaded in the html and I want to apply mosaic-flow to them when I click a certain button.

So when I click the button, mosaic-flow is initialized, but this causes all the images to become hidden UNTIL I resize the browser window. After resizing, they all just "pop up" and everything looks and works great. It's the initial invisibility that's annoying me.

Any idea what might be the problem? Something in your code or have I missed something very basic? I want to be able to initialize mosaic-flow after a button is pressed, without the images dissapearing.

Adding Elements

Hey (-:

I love Mosaicflow but there is one Problem. When i add (container.mosaicflow('add', elm);) new Items they will be show only in the left column. What can i Do?

image

Rebuild Gallery Trigger

Hi, is it currently possible to rebuild the gallery after it has been built?
Basically I have a gallery with items that have been starred I want to remove the items but it is leaving empty columns and the items aren't evenly stacked.

So I was wondering when the items are removed. Id like a rebuild gallery columns feature?

Thanks,

  • Craig

hiding images until fully loaded

Hi,

This is a great mosaic grid but I'm getting an issue where the other elements on my site get moved around until all the images have loaded - I also sometimes get a small text message appear although it disappears before I can read it - I think it mentions "not responding".

I saw that you suggested in another post it would be possible to hide the mosaic until it's fully loaded but I wasn't sure how to do this. Is it possible and could you show me where I'd need to put the code to make it happen.

Many thanks.

this.items.add(elem) does not actually add elem to list of items

Hi

Took me a while to figure out to Google down this path, but it seems that .add() constructs a new jQuery object, and does not modify the existing object you're adding to. The end result is that if you're dynamically adding objects, and then resizing the window until you 'lose' a column, you actually lose all the items in that column.

I believe that line 233 should be changed to

this.items = this.items.add(elm);

I've tested this and it fixes the issue of losing items.

Smooth breakpoint

Hi @sapegin

great tool – that's exact what I'm looking for. But is there a way that the items "slides" under the others not just jumping if there's a breaktpoint?

Thanks for your help so far.

No Success for Me

I'm not having any success with this.

I copied and pasted the css into my stylesheet. The script file is loaded in the footer and the code is structured like so:

<div class="album clearfix mosaicflow">
    <div class="mosaicflow__item">
        <img width="500" height="300" src="1.jpg" alt="">
    </div>
    <div class="mosaicflow__item">
        <img width="500" height="300" src="2.jpg" alt="">
    </div>
    <div class="mosaicflow__item">
        <img width="500" height="300" src="3.jpg" alt="">
    </div>
</div>

Then I tested it because your directions say "Don’t add .mosaicflow class when you manually initialize Mosaic Flow—it will make Mosaic Flow initializes twice." Which lead me to believe that I didn't need this script:

$('#mycontainer').mosaicflow({
    itemSelector: '.item',
    minItemWidth: 300
});

It didn't do anything. So I added the above script without changing the output code above. Switched "#mycontainer" to ".album" and nothing happened. I was getting an error so I changed the script and didn't get an error with this code but it still didn't create any columns:

$('.album').mosaicflow({
    minItemWidth: 300
});

Do you have any idea what I'm doing wrong?

Created columns are not updated properly after resize

In case "calculatedCnt < createdCnt" line 129, Columns should be updated.

Line 108 // Remove excess columns
Line 109 this.columns = this.columns.filter(':hidden').remove();
Line (new) this.columns.css('width', (100 / calculatedCnt) + '%');

HTML5 data attributes?

Hi,

LOVE this plugin. Thank you for sharing. :octocat:

Stupid question: Your README says:

You can difine options via HTML data attributes or via JavaScript object (manual initialization).

<div class="clearfix mosaicflow" item-selector=".item" min-item-width="300">

I've always seen HTML5 data attributes start with data-. I did not realize this was optional?

I'm probably just not familiar with all the ways one can create custom HTML5 data- attributes. 😄

Related: You might find this of interest.

I wrote this stupid plugin a while back:

https://github.com/registerguard/jquery-kerplop

... it's the first time I've used custom HTML5 data- attributes in a jQuery plugin. Example:

<div class="kerplop" data-kerplop-from="outgoing" data-kerplop-use="prepend"></div>

... which works great.

Well, I recently discovered that I can have one custom attribute that contains a JSON object, like so:

<div class="kerplop" data-kerplop='{"from" : "xxx", "use" : "xxx"}'></div>

The cool thing, I think, about the above, is that I'm able to keep the markup clean and the data-attribute is namespaced with the name of my plugin (less of a chance of a collision with other people's code).

Not sure if that info is of interest to you ... Just seems like your plugin would be even cooler to do something like:

<div class="clearfix mosaicflow" data-mosaicflow='{"item-selector" : ".item", "min-item-width" : "300"}'>...</div>

... at least, that's how I plan on doing all future plugins that utilize custom HTML5 data- attributes.

Anyway, love this plugin! Awesome work!!!!! Thank you!

Video

Van this be used with video

Sane event names

  • mosaicflow-layout → layout.mosaicflow
  • start → start.mosaicflow
  • etc.

README: You can use bare <img> tags or arbitrary HTML.

Hello,

From the README:

You can use bare <img> tags or arbitrary HTML.

That's a little unclear to me. Could you elaborate?

Does that mean my image tags don't need to have div wrappers?

Mostly curious what "bare <img> tags" means.

Again, love this plugin!

Thanks!

clearfix class

In your html you use a clearfix class on the top div (see below), but your example css does not have a clearfix item. I was wondering what clearfix css were you using?

Thank you

<div class="clearfix mosaicflow">

Append items in mosaicflow with ajax

Hi, i like to append my mosaicflow list with new items after i clicked on a button with an ajax call, but i can' figure it out how it can work correctly..
I tried to use the add event, but it adds items only to the smallest column not to every column.
Do you have any ideas to solve this?

Thanks in advance!

iPad rotation bug

Hi

I had been fighting with this plugin bug for the past few days on ipad.

I have a list which expected to split to 2 columns in landscape and back to 1 column in portrait. But the result is that it will on every alternative change from portrait to landscape show only one column instead of 2.

I still can't find out why every alternative change from portrait to landscape. But I can see that you only remove the hidden column on the next visit to the refill() function and on the instance that show 1 column in landscape, desktop browser tend to fire refill() twice which will cover the incapability to render properly of the list in the first call of refill(). This however is not same situation for iPad. refill() only fire once and by the time refill() is able remove the hidden column it is already too late because all the items already got into the first column.

Long story short, eventually I came up with this solution which will solve my problem and possibly other people's:

At the first line of the ensureColumns() function, I will use the following line instead of the orginal one.
var createdCnt = this.columns.filter(':visible').length;

This is to filter out those are not viewable (anyway) and count those visible, before the unused column really get deleted.

Hop this can help
D.

How to destroy the Plugin?

How to destroy the Plugin?

i have multiple gallery to show dynamically but one at time.
so i have to destroy from one gallery and to recreate the plugin again for other. (assume its like a tabs).
photos will be loaded dynamically when we switch from one tab to other.

Mosaicflow with ng-repeat

When I use mosaicflow with ng repeat, it does not work well and I don't know what I'm doing wrong.
Below is my code:

 <div class="clearfix mosaicflow" data-min-item-width="230">
    <div>
      <div class="mosaicflow__item" data-ng-repeat="image in images">
        <a href="gallery_detail.html"> <img src="[[ image.image ]]" alt=""></a>
        <p>[[ image.name ]]</p>
      </div>  
    </div>
  </div>

and the code generated by the browser:

<div class="clearfix mosaicflow" data-min-item-width="230" style="visibility: visible;">
  <div style="visibility: hidden; width: 100%;"></div>
    <div class="mosaicflow__column" style="width: 33.3333%;">
      <div id="mosaic-0-itemid-1">
      <!-- ngRepeat: image in images -->
        <div class="mosaicflow__item ng-scope" data-ng-repeat="image in images">
          <a href="gallery_detail.html"> 
            <img src="" alt="" data-pin-nopin="true">
          </a>
          <p class="ng-binding"></p>
        </div>
       <!-- end ngRepeat: image in images -->
        <div class="mosaicflow__item ng-scope" data-ng-repeat="image in images">
          <a href="gallery_detail.html"> 
            <img src="" alt="" data-pin-nopin="true">
         </a>
         <p class="ng-binding"></p>
       </div>
       <!-- end ngRepeat: image in images -->
       <div class="mosaicflow__item ng-scope" data-ng-repeat="image in images">
          <a href="gallery_detail.html"> 
            <img src="" alt="" data-pin-nopin="true">
           </a>
          <p class="ng-binding"></p>
       </div>
       <!-- end ngRepeat: image in images -->
       <div class="mosaicflow__item ng-scope" data-ng-repeat="image in images">
          <a href="gallery_detail.html"> 
            <img src="" alt="" data-pin-nopin="true">
          </a>
          <p class="ng-binding"></p>
       </div>
      <!-- end ngRepeat: image in images -->
    </div>
  </div>
  <div class="mosaicflow__column" style="width: 33.3333%;"></div>
  <div class="mosaicflow__column" style="width: 33.3333%;"></div>
</div>

I do not know why the columns appear at the end of the code.

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.