media queries - javascript - detect which view? -
this question has answer here:
- get device width in javascript 5 answers
i using @media queries in css responsive design. need 1 breakpoint.
how use javascript detect state page in @ given moment (ideally when resizing window)?
based on state (eg. below 640px width or over), run different js function.
thank you
with breakpoint @ 640px use following code execute different functions depending on current view.
function executemqdependentcode() { var mq = window.matchmedia( "(min-width: 640px)" ); if (mq.matches) { // code wide screens } else { // code smaller screens } }
if want have code executed when user resizes window, add event listener:
window.onresize = executemqdependentcode;
Comments
Post a Comment