Run javascript/jquery only on screen media, not print

前端 未结 3 915
悲&欢浪女
悲&欢浪女 2020-12-19 01:41

How can I run a jquery function only on @media screen?

Background:

I have a screen.css stylesheet and a print.css styl

3条回答
  •  眼角桃花
    2020-12-19 02:08

    I think you could use Modernizr. Although, there must be a native way to do it in javascript.

    http://modernizr.com/docs/#mq

    I have never tried it but it is something like this:

    if (Modernizr.mq('only screen'))
    {
    ..
    }
    

    beware with old browsers not supporting media queries.

提交回复
热议问题