2013-01-16 4 views
0

J'essaie des requêtes média avec jQuery mais ne fonctionne pas correctement.Pourquoi ne pas utiliser les requêtes multimédias dans jQuery?

if ((screen.width>=20) || (screen.width<300)){ 
     width="190"; //Adjust the width of the image 
     height="170"; //Adjust the height of the image 
    } 
    if ((screen.width>=300) || (screen.width<350)){ 
     width="240"; height="200"; 
    } 
    if ((screen.width>=351) || (screen.width<400)){ 
     width="280"; height="220"; 
    } 
    if ((screen.width>=401) || (screen.width<599)){ 
     width="320"; height="240"; 
    } 
    if ((screen.width>=600) || (screen.width<757)){ 
     width="440"; height="320"; 
    } 
    if ((screen.width>=758) || (screen.width<899)){ 
     width="320"; height="240"; 
    } 

Le code est appelé lorsqu'un plugin est chargé car un nouveau contenu a été ajouté. C'est une application d'une seule page. Le contenu est chargé sans actualiser le navigateur. J'ai besoin d'utiliser des mediaqueries avec jquery car width et height sont des variables du plugin.

Une idée? Merci

+1

Qu'est-ce que 'screen'? D'où vient-il? Voulez-vous dire '$ (window) .width()' et '$ (window) .height()'? –

+0

Qu'est-ce que 'screen'? Est-ce que 'screen' est un objet jQuery? Quel est le plugin de toute façon? – Alexander

+1

Si vous recherchez des mediaqueries que jQuery/Javascript peut évaluer, utilisez la méthode mq() du plugin Modernizr: http://modernizr.com/docs/#mq – saschoar

Répondre

1

Est-ce que vous avez voulu?

if ((window.innerWidth>=20) || (window.innerWidth<300)){ 
     width="190"; //Adjust the width of the image 
     height="170"; //Adjust the height of the image 
    } 
    if ((window.innerWidth>=300) || (window.innerWidth<350)){ 
     width="240"; height="200"; 
    } 
    if ((window.innerWidth>=351) || (window.innerWidth<400)){ 
     width="280"; height="220"; 
    } 
    if ((window.innerWidth>=401) || (window.innerWidth<599)){ 
     width="320"; height="240"; 
    } 
    if ((window.innerWidth>=600) || (window.innerWidth<757)){ 
     width="440"; height="320"; 
    } 
    if ((window.innerWidth>=758) || (window.innerWidth<899)){ 
     width="320"; height="240"; 
    } 
Questions connexes