【问题标题】:Isotope + resize + imageLoaded同位素 + 调整大小 + imageLoaded
【发布时间】:2014-09-10 10:42:30
【问题描述】:

各位帮手你好 :) 我已经实现了一个 wordpress 页面在砖石流体网格中显示图像,但是在 HTML5 中调用视频时遇到问题(仅使用标签:)。问题是图像与宽度完美配合:50%;高度:自动;并且视频加载到其中但不适合砖石布局(它与其他图像重叠)只是当您调整屏幕大小时它适合网格。所以我想我可以通过将 .imageLoaded() 插件添加到同位素调用来解决它,但我不知道什么时候,我的 jQuery 代码如下:

真的提前感谢大家!

$(函数(){

        var $container = $('#container'),
        // create a clone that will be used for measuring container width

            $containerProxy = $container.clone().empty().css({ visibility: 'hidden' });
        $checkboxes = $('#filters input');


        $container.after( $containerProxy );

        // get the first item to use for measuring columnWidth
        var $item = $container.find('.item').not('.w2').eq(0);

        $(window).smartresize( function() {
            // calculate columnWidth
            var colWidth = Math.floor( $containerProxy.width() / 4 );
            // set width of container based on columnWidth
            $container.css({
                width: colWidth * 4
            })
                .isotope({
                    // other options...
                    // disable automatic resizing when window is resized
                    resizable: false,
                    // set columnWidth option for masonry
                    masonry: {
                        columnWidth: colWidth
                    }
                });
            // trigger smartresize for first time
        }).smartresize();

        $checkboxes.change(function(){
            var filters = [];
            // get checked checkboxes values
            $checkboxes.filter(':checked').each(function(){
                filters.push( this.value );
            });
            // ['.red', '.blue'] -> '.red, .blue'
            filters = filters.join(', ');
            $container.isotope({ filter: filters });
        });



    }); 

【问题讨论】:

    标签: jquery css html jquery-isotope jquery-masonry


    【解决方案1】:

    见以下代码:

     $(function(){
    
        var $container = $('#container'),
        // create a clone that will be used for measuring container width
    
            $containerProxy = $container.clone().empty().css({ visibility: 'hidden' });
        $checkboxes = $('#filters input');
    
    
        $container.after( $containerProxy );
    
        // get the first item to use for measuring columnWidth
        var $item = $container.find('.item').not('.w2').eq(0);
    
        $(window).smartresize( function() {
            // calculate columnWidth
            var colWidth = Math.floor( $containerProxy.width() / 4 );
            // set width of container based on columnWidth
    
          $container.imagesLoaded( function(){  //Add Imagesloaded here
    
    
            $container.css({
                width: colWidth * 4
            })
                .isotope({
                    // other options...
                    // disable automatic resizing when window is resized
                    resizable: false,
                    // set columnWidth option for masonry
                    masonry: {
                        columnWidth: colWidth
                    }
                });
            // trigger smartresize for first time
        }).smartresize();
    
        $checkboxes.change(function(){
            var filters = [];
            // get checked checkboxes values
            $checkboxes.filter(':checked').each(function(){
                filters.push( this.value );
            });
            // ['.red', '.blue'] -> '.red, .blue'
            filters = filters.join(', ');
            $container.isotope({ filter: filters });
        });
    
         }); //imagesloaded end
    
       }); 
    

    【讨论】:

    • 不知道为什么,但它也破坏了砌体布局。 :(
    • 你是在同位素之前加载脚本 imagesloaded.pkgd.min.js 吗?
    • 是的,我在同位素之前加载 imagesloaded.pkgd.min.js。