0

I'm using https://github.com/GBKS/Wookmark-jQuery to do some dynamic layout, i'm also attaching a function on window resize:

var $windowWidth = $window.width();
var options = {
        itemWidth: 100, 
        autoResize: true, 
        container: $('#tiles'), 
        offset: 5, 
        outerOffset: 0, 
        flexibleWidth: '30%' 
    };

if ($windowWidth >= 768 && $windowWidth <= 1200) {
    options.itemsize = 200;
    options.offset = 7;
} else if ($windowWidth > 1200) {  
    options.itemsize = 300;
    options.offset = 10;
}

$('#tiles li').woodmark(options); <-- this is fine

but i want to create a function to return the properties:

function getOptions() {
    var $windowWidth = $(window).width();
    var sizes = {
       itemsize: 100,
       offset: 5,
       autoResize: true, 
       outerOffset: 0,
       flexibleWidth: '30%' 
       }; 

    if ($windowWidth >= 768 && $windowWidth <= 1200) {
        sizes.itemsize = 200;
        sizes.offset = 7;
    } else if ($windowWidth > 1200) {
        sizes.itemsize = 300;
        sizes.offset = 10;
    }
   return sizes;
}

$('#tiles li').wookmark(getOptions); <-- doesn't work
$('#tiles li').wookmark(function() { getOptions }); <-- doesn't work

all the code samples in wookmark are done as a jquery plugin, and normal breakpoint doesn't work in chrome inspector..

4

1 回答 1

0

您需要传递.wookmark()一个对象,而不是一个函数。调用时,getOptions()返回一个对象。当你这样做$('#tiles li').wookmark(getOptions);时,插件不知道如何处理你传递给它的函数,它想要一个对象。

尝试这个:

$('#tiles li').wookmark(getOptions());
于 2014-01-17T16:11:02.343 回答