媒体查询调试

时间:2011-10-02 04:12:08

标签: javascript css layout

我尝试创建一个响应式网站,并且需要查看我当前布局中的分页符,然后我想到了一些东西,告诉我它会在每个窗口中调整当前窗口大小。 我看到有人在this帖子中讲述了响应式布局。关于函数here的链接。 我发现这个代码但是无法上班,现在是01:09,是在巴西的夜晚和我疯狂。有人可以帮帮我吗?我在铬测试。作者告诉它将当前大小放在em的页面一角;

<html>
    <head>
        <title>MediaQuery DBG</title>
        <SCRIPT LANGUAGE="JavaScript" SRC="http://code.jquery.com/jquery-1.6.4.js"></SCRIPT>
        <script type="text/javascript">
            $(document).ready(function() {
                var step = 1;
                var start = 1;
                var end = 2048;             
                var unit = "em";
                var command = "";
                var expression = "";
                for (cs=start;cs<=end;cs=cs+step)
                {
                    expression = "screen and (min-device-width: "+(cs-step)+unit") and (max-device-width: "+(cs)+unit")";
                    command = "var mql = window.matchMedia("+expression+");" +
                              "function handleOrientationChange(mql) {" + 
                                "   if (mql.matches) {" + 
                                "       $(\"#lblmq\").replaceWith( \"<div id='lblmq'>tamanho: "+cs+"</div>\" ); " + 
                                "   }" + 
                                "}";
                    command = "mql.addListener("+command+");"
                    eval(command);

                });     
        </script>
        <style>
            #lblmq
            {
                background-color: #789;
                width:20em;
            }
        </style>
    </head>
    <body >
        <div id='lblmq'></div>
    </body>     
</html>