Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery browser resize initiating function
    primarykey
    data
    text
    <p>I have the below function which works as expected on document ready but on resize it doesn't register the size change and executes the alert for the size before the resize. Ive added the <code>menuInitialized</code> as a flag to try and combat the issue but now it initializes multiple times. For example it will alert "Small", "Large", "small" If I resize the browser multiple times.</p> <pre><code>var menuInitialized = false; function doMenu() { var left = $('.c_left').height(); var right = $('.c_right').height(); if (left &gt; right) { $('.c_right').css('height', left + 'px'); } $(".c_left, .top_right, .c_right, .c_myaccount, .header_image, .c_footer, .copyright, .accepts, .myaccount, .header_logo").removeAttr('style'); var $menu = $(".c_left"); var width = $(window).width(); var status = 'closed'; var width = $(window).width(); if (width &lt; 550) { if (!menuInitialized) { $('.icon-menu-2').on('click', function(event) { alert('small'); if (status === 'closed') { $menu.animate({ width: 185, marginLeft: 0, display: 'toggle' }, 'fast'); $(".top_right, .c_right, .c_myaccount, .c_footer, .copyright, .accepts").animate({ marginLeft: 185, display: 'toggle' }, 'fast'); $(".myaccount").animate({ marginRight: -185, display: 'toggle' }, 'fast'); return status = 'open'; } else if (status === 'open') { $menu.animate({ width: 0, marginLeft: -185, display: 'toggle' }, 'fast'); $(".top_right, .c_right, .c_myaccount,.c_footer, .copyright, .accepts").animate({ marginLeft: 0, display: 'toggle' }, 'fast'); $(".myaccount").animate({ marginRight: 0, display: 'toggle' }, 'fast'); return status = 'closed'; } }); menuInitialized = true; } } else if ((width &lt; 800) &amp;&amp; (width &gt; 550)) { if (menuInitialized) { $('.icon-menu-2').on('click', function(event) { alert('large'); if (status === 'closed') { $menu.animate({ width: 185, marginLeft: 0, display: 'toggle' }, 'fast'); $(".top_right, .c_right, .c_myaccount, .header_image, .c_footer, .copyright, .accepts").animate({ marginLeft: 185, display: 'toggle' }, 'fast'); $(".myaccount, .header_logo").animate({ marginRight: -185, display: 'toggle' }, 'fast'); return status = 'open'; } else if (status === 'open') { $menu.animate({ width: 0, marginLeft: -185, display: 'toggle' }, 'fast'); $(".top_right, .c_right, .c_myaccount, .header_image,.c_footer, .copyright, .accepts").animate({ marginLeft: 0, display: 'toggle' }, 'fast'); $(".myaccount, .header_logo").animate({ marginRight: 0, display: 'toggle' }, 'fast'); return status = 'closed'; } }); menuInitialized = false; } } } $(document).ready(doMenu); $(window).resize(doMenu); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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