Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在调整窗口大小时运行脚本?_Javascript_Jquery_Responsive Design_Window Resize_Onresize - Fatal编程技术网

Javascript 如何在调整窗口大小时运行脚本?

Javascript 如何在调整窗口大小时运行脚本?,javascript,jquery,responsive-design,window-resize,onresize,Javascript,Jquery,Responsive Design,Window Resize,Onresize,我使用Jquery在重新调整大小时保持纵横比。在小屏幕上,我想在另一个类上使用这个脚本。在第一次加载时,一切似乎都很好 但是,当我将窗口从大>768调整到小

我使用Jquery在重新调整大小时保持纵横比。在小屏幕上,我想在另一个类上使用这个脚本。在第一次加载时,一切似乎都很好

但是,当我将窗口从大>768调整到小<767时,除非重新加载,否则脚本将无法工作。奇怪的是,当我在一个小窗口768中加载站点时,脚本确实可以工作,并且在重新调整大小时仍然可以工作。你知道怎么解决这个问题吗

if ($(window).width() > 768) {
    /* square featured-column1 box aanpassing */
    equalheight = function(container) {
        var currentTallest = 0,
            currentRowStart = 0,
            rowDivs = new Array(),
            $el,
            topPosition = 0;
        $(container).each(function() {
            $el = $(this);
            $($el).height('auto')
            topPostion = $el.position().top;

            if (currentRowStart != topPostion) {
                for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
                    rowDivs[currentDiv].height(currentTallest);
                }
                rowDivs.length = 0; // empty the array
                currentRowStart = topPostion;
                currentTallest = $el.height();
                rowDivs.push($el);
            } else {
                rowDivs.push($el);
                currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
            }
            for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
                rowDivs[currentDiv].height(currentTallest);
            }
        });
    }
    $(window).load(function() {
        equalheight('.featured-column');
    });

    $(window).resize(function() {
        equalheight('.featured-column');
    });
    /* Aspect ratio box (responsive rechthoek) aanpassing */
    $(document).ready(function() {
        aspectResize();
        $(window).resize(aspectResize);
    });
    aspectResize = function() {
        var $aspect = $('div.up-to-date-bar');
        var width = $aspect.width();
        $aspect.height(width / 3 * 1);
    }
}
/* Aspect ratio box (responsive rechthoek) aanpassing up-to-date-column*/
if ($(window).width() < 767) {
    $(document).ready(function() {
        aspectResize();
        $(window).resize(aspectResize);
    });
    aspectResize = function() {
        var $aspect = $('div.up-to-date-column');
        var width = $aspect.width();
        $aspect.height(width / 1 * 1);
    }
}
您可以使用在调整窗口大小时调用函数

$( window ).resize(function() {
    // Your code here
});

没有注意到下面有更多的代码。-你能在JSFIDDLE中重现这个问题吗?这是你想要的吗?在你的链接中添加一点上下文会很有帮助-这正是“每个人”想要的:我是众多幸运的用户之一,能够在这个网站上审查低质量的问题和答案。您的答案已标记以供审阅。当我告诉评论系统你的答案不应该被删除,但需要做一些工作时,我留下的评论是由评论系统自动生成的。感谢您花时间添加上下文-这一切都有助于使网站变得更好。我使用$window.resizefunction再次运行纵横比框脚本,它在调整大小时起作用。还有一件事,当我使用较小的窗口按钮打开窗口时,如果您想手动触发调整大小处理程序,比如在初始页面加载时,您可以使用$window.resize。在没有看到你的网站运行的情况下,很难知道到底发生了什么。希望这能有所帮助。