css - Combine @media with javascript to set display none/block -


i have div panel somewhere on page should hidden when window size gets small.

works fine using css:

#panel {display: block; }  @media (max-width: 1000px) {    #panel { display: none; } } 

there rule displays button should make #panel visible onclick.

#panel {display: block; } #button {display: none; } @media (max-width: 1000px) {    #panel { display: none; }    #button {display: block; } } 

the javascript looks this:

 $("#button").click(function() { $("#panel").toggle(); }); 

there other rules make panel appear friendlier... no need explain this. problem is: when once clicked button , changed display state of panel on , off again. means display:none property set javascript, panel not displayed again when resize window > 1000px. default style of panel not applied, if create rule @media(min-width: 1000px).. js seems have priority.. best way combine media queries , js?

you add event listener window resize event forces panel visible when window resized width > 1000px.

$(window).on('resize', function() {     if (window.innerwidth > 1000) {         $("#panel").show();     } }); 

as toggle, show, or hide called trump whatever in css.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -