Giter Site home page Giter Site logo

Layout fails on reload about packery HOT 12 CLOSED

metafizzy avatar metafizzy commented on May 28, 2024
Layout fails on reload

from packery.

Comments (12)

desandro avatar desandro commented on May 28, 2024

Try using imagesLoaded. See http://packery.metafizzy.co/appendix.html

from packery.

alexmorris avatar alexmorris commented on May 28, 2024

Not sure that'd be it. The issue happens when images are already cached. Happens locally too.

from packery.

kokarn avatar kokarn commented on May 28, 2024

I had similar problems even with imagesLoaded.

I fixed the problem by doing the layout on window load instead of document ready so that every resource is loaded, even fonts and such.

from packery.

alexmorris avatar alexmorris commented on May 28, 2024

ahh cool - can you point me at an example?

from packery.

kokarn avatar kokarn commented on May 28, 2024

Can't really link to the project as it in production, but the code we ended up using is this

$( window ).load(function(){
   var $content = $( '#content' );
   $content.packery({
        itemSelector : '.post-wrapper',
        columnWidth : 300,
        gutter: 20
   });
});

from packery.

desandro avatar desandro commented on May 28, 2024

Good news is that imagesLoaded is getting a rewrite and cached images should be resolved. See desandro/imagesloaded#65 . Expect imagesLoaded v3 out in the next 10 days.

from packery.

alexmorris avatar alexmorris commented on May 28, 2024

For now the window.load technique works fine with webfonts and cached images.

    <script>
        (function ($) {
            $(window).load(function () {
                var $container = $('#content');
                // initialize
                $container.packery({
                  itemSelector: '.item',
                  columnWidth: '.grid-sizer'
                });
            });
        }(jQuery));

    </script>

from packery.

RyGa avatar RyGa commented on May 28, 2024

How do you specify packery options (like itemSelector, transitionDuration etc) whilst using the imagesloaded method?

I saw this, but not sure how i add in my options..

var container = document.querySelector('#container');
var pckry;
// initialize Packery after all images have loaded
imagesLoaded( container, function() {
pckry = new Packery( container );
});

from packery.

desandro avatar desandro commented on May 28, 2024

@RyGa

var container = document.querySelector('#container');
var pckry;
// initialize Packery after all images have loaded
imagesLoaded( container, function() {
  pckry = new Packery( container, {
    // options...
    itemSelector: '.item',
    transitionDuration: '0.8s'
  });
});

from packery.

RyGa avatar RyGa commented on May 28, 2024

Thank you this works fine, and fixes packery not sizing container properly when images have not been downloaded yet.

Although must we use document.querySelector('#container'); ?
I tried jq method: var container = $('#container');
it gives error: Bad packery element: [object Object]

works fine using document.queryselector though, just wondering is all.

from packery.

desandro avatar desandro commented on May 28, 2024

If you're using jQuery, you can do it like so:

var $container = $('#container');

// initialize Packery after all images have loaded
$container.imagesLoaded( function() {
  $container.packery({
    // options...
    itemSelector: '.item',
    transitionDuration: '0.8s'
  });
});

from packery.

 avatar commented on May 28, 2024

I would like to refresh the window size for packery. I have a click event that does display:none;. On this click I want packery to refresh. I have tried $(window).resize(); but with no luck. Are there any events in packery that call to refresh?

from packery.

Related Issues (20)

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.