Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Masonry Plugin and Dynamic Stylesheets
    text
    copied!<p>I have a page layout that needs to reduce from a 3 column layout to a 2 column layout depending on the browser size. I am also using the <a href="http://masonry.desandro.com/" rel="nofollow">jQuery masonry plugin</a> to keep my grid of containers on the page arranged nicely. This all works fine on window resize. </p> <p>The problem I am having is that if I load the page at the size smaller than 1100px it correctly calls the 'col2.css' stylesheet using jQuery, but the masonry plugin thinks it's still a 3 column layout until you manually resize the browser so the grid is still at the col3 width and goes off the size of the container.</p> <p>I'm guessing I need to somehow call the masonry function after jQuery has chosen the stylesheet, but I don't know how to do this.</p> <p>I have this in my head</p> <pre><code>&lt;link href="&lt;?=base_url()?&gt;inc/css/col3.css" id="size-stylesheet" rel="stylesheet" type="text/css" /&gt; </code></pre> <p>and the following javascript</p> <pre><code> $(document).ready(function() { function adjustStyle(width) { width = parseInt(width); if (width &lt; 1100) { $("#size-stylesheet").attr("href", "inc/css/col2.css"); } else { $("#size-stylesheet").attr("href", "inc/css/col3.css"); } } $(function() { adjustStyle($(this).width()); $(window).resize(function() { adjustStyle($(this).width()); }); }); //masonry $(function(){ $('#masonry').masonry({ itemSelector : '.project', columnWidth : 365, isAnimated: true }); }); }); </code></pre> <p>Any help would be greatly appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload