简体   繁体   English

使JS响应屏幕宽度

[英]Make JS Respond To Screen Width

I am having trouble with getting my JS to respond to browser size. 我在让JS响应浏览器大小方面遇到麻烦。 To give an idea of what I am working on, my updated JS Fiddle can be found at the link http://jsfiddle.net/T5CqA/1/ . 为了大致了解我的工作,可以在链接http://jsfiddle.net/T5CqA/1/中找到更新的JS Fiddle。

The original code is as follows; 原始代码如下: ` $(document).ready(function(){ `$ {document).ready(function(){

            $('#myDeepMenu').deepMenu({"tileW":64,"tileH":100,
                                       "columns":2,"rows":2,
                                       "mark-type":"top-left",
                                       "mark-color":"#A1A1A1"});
        });

When you click on the icons (there are no icons at the moment), several image menus pop up. 当您单击图标时(目前没有图标),将弹出几个图像菜单。 The arrangement of these icons is dictated by the "Row" and "Column" portion of the Javascript. 这些图标的排列由Javascript的“行”和“列”部分决定。 I am having trouble getting the values to change based on screen resize. 我无法根据屏幕调整大小来更改值。 I want the colums and row arrangement to be different so that they fit screen size. 我希望列和行的排列不同,以使其适合屏幕尺寸。

For instance, going from a single row and column to several when the screen gets smaller. 例如,当屏幕变小时,从单个行和一列变为多个。

Here's a jQuery module I like to include into development sites I am working with resizing the window so that I can see the value in the console and use the returned value from checkWidth() to make calculations. 这是我要包含在开发站点中的jQuery模块,我正在调整窗口的大小,以便可以在控制台中看到该值,并使用来自checkWidth()的返回值进行计算。

jQuery(function($){

    //store the reference outside the event handler:
    var $window = $(window);

    function checkWidth() {
        var windowSize = $window.width();

        return windowSize;
    }

    // Execute on load
    checkWidth();

    // Bind event listener to window resize
    $(window).resize(function(){
            //remove console.log from production version - useful for while in development
        console.log('checkWidth: ', checkWidth() + 'px' );
    });

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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