jQuery Masonry and media queries - reload masonry

﹥>﹥吖頭↗ 提交于 2019-12-10 14:26:51

问题


i have my site designed with media queries to cover different-sized layouts. i have masonry organizing a bunch of floats at the full-size width, no problem. at the mobile widths, all the floats, unfloat and just stack on top of each other. so i only need to re-run masonry when the site resizes to the tablet layout when 768px <= width <= 1000px.

<script type="text/javascript">
//<![CDATA[

    $(document).ready(function($){

        $('ul.xoxo').masonry({ singleMode: true, itemSelector: '.widgetcontainer'  });

        //If the User resizes the window, adjust the #container height
        $(window).bind("resize", resizeWindow);
        function resizeWindow( e ) {
            var newWindowWidth = $(window).width();

            if(newWindowWidth<1008){
                $('ul.xoxo').masonry();
            } else {
                $('ul.xoxo').masonry();
            }
        }

    });

/* ]]> */
</script>

which doesn't work for me yet, but also i don't want it running on all resizes... just at the break points.


回答1:


You can use Masonary's isResizable option for these cases.

  $container.masonry({
    itemSelector: '.box',
    isResizable: true
  });



回答2:


a better solution for what i was trying to do is called Isotope, which works better on resize

http://isotope.metafizzy.co/



来源:https://stackoverflow.com/questions/5849535/jquery-masonry-and-media-queries-reload-masonry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!