简体   繁体   中英

javascript/jquery plugin to add support to media queries

found out about this jquery plugin that adds support to media queries

So you can use:

<link rel="stylesheet" type="text/css" href="wider.css" media="only screen and (min-width: 1200px)" /> 
<link rel="stylesheet" type="text/css" href="handheld-iphone.css" media="only screen and (max-width: 480px), handheld" />

and so on, but it does not support this kind of media queries (in stylesheet)

@media screen and (max-width: 1024px) {
    body{background:red}
}
@media screen and (max-width: 740px) {

    body{background:yellow}
}

Is there any that does?

你应该看看enquire.js

You could do something like this as well

http://jsfiddle.net/47DSD/

 $(document).ready(function() {

     function wResize() {

             var winW = $(window).width();
             var Body = $('body');

         if ( winW < '1024') {
             Body.css({ 'background-color':'red' }); 
         }
         if ( winW < '740' ) {
             Body.css({ 'background-color':'yellow' }); 
         }         

     }

     wResize();

    $(window).resize(function() {
        wResize();
    });

 });

Edit:

You didnt seem to warm up to this, so how about a little more extensive example?

http://jsfiddle.net/47DSD/1/

Wouter van der Graaf made a javascript plugin for media query support in browsers that don't natively support it:

http://code.google.com/p/css3-mediaqueries-js/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM