Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery isotope on first load doesn't work, How do I wait for all resources/images to be loaded?

I've got something I've put together using jQuery isotope here.. http://jsbin.com/eziqeq/6/edit

It seems to work in general but on first load, of a new tab, the Isotope plugin is setting the height of the wrapper element to 0. If I refresh the page it does work and sets the height of the parent element based on the the items found inside.

Any help would be greatly appreciated. I can't think why off this first load this isn't working and on subsequent reloads it is.. unless its perhaps something to do with caching the images it loads?

EDIT--

This is a caching issue in Webkit browsers as it works on Firefox and on a working tab when I clear the cache and refresh the page it won't work until refreshed again.

like image 880
Keith Mason Avatar asked Jan 04 '13 14:01

Keith Mason


People also ask

How do I use isotope in jQuery?

You can use Isotope as a jQuery plugin: $ ( 'selector' ).isotope (). You can use Isotope with vanilla JS: new Isotope ( elem, options ) . The Isotope () constructor accepts two arguments: the container element and an options object. You can initialize Isotope in HTML, without writing any JavaScript.

How do I add isotope to my website?

Include the Isotope .js file in your site. Isotope works on a container element with a group of similar child items. All sizing of items is handled by your CSS. You can use Isotope as a jQuery plugin: $ ( 'selector' ).isotope (). You can use Isotope with vanilla JS: new Isotope ( elem, options ) .

How to use isotope with Vanilla JS?

You can use Isotope with vanilla JS: new Isotope (elem, options). The Isotope () constructor accepts two arguments: the container element and an options object. var elem = document.querySelector ('.grid'); var iso = new Isotope(elem, { itemSelector: '.grid-item', layoutMode: 'fitRows' }); var iso = new Isotope('.grid', { });

What is the difference between HTML and JSON isotope?

Note the HTML attribute data-isotope is set with single quotes ', but JSON entities use double-quotes ". Learn more about how to use Isotope:


1 Answers

There is another option to solve this issue. You have to use another one js if your grid-item contain any image. below the js link is

<script src='http://imagesloaded.desandro.com/imagesloaded.pkgd.js'></script>

Then call this placeholder js below:

/*=============Code for Masonry Gallery ==============*/
    var grid = document.querySelector('.grid');
    var jQuerygrid = jQuery('.grid').isotope({
        itemSelector: '.element-item'
    }); 
    var iso = jQuerygrid.data('isotope');
    jQuerygrid.isotope( 'reveal', iso.items );

    imagesLoaded(grid, function(){
        iso.layout();
    });

You can get full and clear details from isotop's official website. link

like image 65
Sarower Jahan Avatar answered Sep 21 '22 20:09

Sarower Jahan