0

所以我正在尝试做这样的事情:http: //prothemeus.com/demo/litho/

我遇到过: http ://masonry.desandro.com/、http : //isotope.metafizzy.co/http://packery.metafizzy.co/,它们都非常相似,但没有一个提供像顶部的网站一样缩放。我将如何使用这些插件之一创建类似的东西,或者有人知道默认情况下提供缩放以适应容器的选项吗?

就演示而言,我能够发现 isotope 处理布局,但我无法追踪进行实际缩放的代码。

任何帮助将不胜感激。

4

2 回答 2

1

我最终忽略了所有插件,只有我缩小的 smartresize,因为它在我找到它的任何地方都未压缩。不确定它是来自 Paul Irish 还是其他人,无论哪种方式,这都是它的 jsfiddle。http://jsfiddle.net/matthewabrman/6R2DU/

//smartresize
(function(e,t){var n=function(e,t,n){var r;return function(){function u(){if(!n)e.apply(s,o);r=null}var s=this,o=arguments;if(r)clearTimeout(r);else if(n)e.apply(s,o);r=setTimeout(u,t||100)}};jQuery.fn[t]=function(e){return e?this.bind("resize",n(e)):this.trigger(t)}})(jQuery,"smartresize")

function redraw_UI() {
    var content_width = $('.content').width()+20;
    images_per_row = Math.floor(content_width / 240);
    var width = Math.round(content_width / images_per_row);
    var height = Math.round(width/3*2);
    $('.content .item').each(function(id){
        var x = Math.round((id % images_per_row) * width);
        var y = Math.floor(id/images_per_row) * height + Math.floor(id/images_per_row) * 20;
        if (navigator.appName.indexOf("Internet Explorer")!=-1){
            $(this).animate({width: width-20+'px', height: height+'px', left: x, top: y},600);
        } else {
            $(this).css({'width': width-20+'px', 'height': height+'px', 'left': x, 'top': y });
        }
    });

    if (images_per_row == 1) {
        closeImagePreview();
    }
}

$(window).smartresize(redraw_UI);
$(window).ready(redraw_UI);
于 2014-04-11T18:48:48.753 回答
0

砌体使用以下bindResize方法支持这一点:http: //masonry.desandro.com/methods.html#bindresize

$container.masonry(options);
$container.masonry('bindResize')

这将触发调整大小的布局。你也可以做

$(window).resize(function () {
   $container.masonry();
});

这将触发重新布局,但您应该限制它以避免它被称为 offten。默认情况下,这将缩放以适应容器。

然后您要做的是使容器响应,以便它根据窗口大小调整大小。为此,您可以查看引导程序或自己滚动。

于 2014-04-10T18:28:02.447 回答