desandro / masonry

:love_hotel: Cascading grid layout plugin
https://masonry.desandro.com
16.38k stars 2.11k forks source link

Uncaught TypeError: Cannot set property 'position' of undefined #1084

Closed Lucbug closed 5 years ago

Lucbug commented 5 years ago

Hi,

I'm having an issue when initialising my Masonry : Uncaught TypeError: Cannot set property 'position' of undefined at Object.utils.extend.

And the trace takes me to

// extends objects
utils.extend = function(a, b) {
    for (var prop in b) {
        a[prop] = b[prop];
    }
    return a;
};

The a[ prop ] = b[ prop ]; fails at prop = position, when the breakpoint indicates position: 'relative'. Assumingly this is due to

Outlayer.defaults = {
    containerStyle: {
        position: 'relative'
    },
    initLayout: true,
    originLeft: true,
    originTop: true,
    resize: true,
    resizeContainer: true,
    // item options
    transitionDuration: '0.4s',
    hiddenStyle: {
        opacity: 0,
        transform: 'scale(0.001)'
    },
    visibleStyle: {
        opacity: 1,
        transform: 'scale(1)'
    }
};

I don't really know what to debug from there.

Here's my initialisation :

var container = $('.masonry');

containerBricks.imagesLoaded(function() {
    var msnry1 = new Masonry(container, {
        // options
        itemSelector: '.masonry__card',
        percentPosition: true,
        resize: true
    });
});

Could someone indicate the direction?

desandro commented 5 years ago

I'm sorry to see you're having trouble with Masonry. Could you provide a reduced test case? See Submitting Issues in the contributing guidelines.

Lucbug commented 5 years ago

Issue resolved. It was caused by the 3rd line var msnry1 = new Masonry(container, {... Replaced container var by '.masonry' and all went smooth.