簡體   English   中英

為什么不使用jQuery進行媒體查詢?

[英]Why don't work media-queries in jQuery?

我正在嘗試使用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";
    }

加載插件時會調用該代碼,因為已添加了新內容。 這是一個單頁應用程序。 加載內容而無需刷新瀏覽器。 我需要在jquery中使用mediaqueries,因為widthheight是插件的變量。

任何想法? 謝謝

這是你想要的嗎?

    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";
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM