I’m using a viewportWidth script to add/modify elements/content for viewport widths less than 769 pixels.
What happens is that on devices less than 769 pixels width, the text ‘Filter Options’ that appears repeats below itself. I know that my onclick function isn’t the cause of it, but I’m wondering if it’s the ‘if (viewportWidth)’ is causing the problem. Screenshot:
You’re inserting those .filterop elements before .leftcol on every update, but never removing them – resulting in those repeating elements.
Inside the update function, you have an $(document).ready() handler, which doesn’t really make sense here; in fact, it appears that the handler gets executed on every update, adding more and more click handlers to the .filterop elements, and thus causing the broken behaviour @Mittineague described.
I assume you’re executing the update function on resize. Note that in practice, a device width rarely changes during a user session. If you want to account for orientation changes, you might be much better off using CSS media queries for this, so you don’t have to touch the DOM at all; resize handlers are very expensive.
As m3g4p0p said I’m not sure why you aren’t using media queries for this as that was what they were designed for. The layout you want seems easily achievable with a few media query tweaks.
If you do need to use js to change something at viewport width then you can use the more efficient matchMedia instead which works for modern browsers.
However, I think you can do everything you want in the normal way.
Try this CSS:
@media screen and (min-width:762px){
.filterop{display:none!important}
}
@media screen and (max-width:761px){
.filterop{display:block}
.leftcol{width:auto;display:table;float:none;margin:0 auto 33px;background:pink;display:none}
.menu-shop-menu-container{float:left;width:48%}
.woof_container_2 {clear:both}
.woof_list_radio li{display:inline-block;width:45%}
}
Remove your mobile resize script and just use this instead .