media queries - javascript - detect which view? -


this question has answer here:

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

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -