Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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
如何正确设置“响应”jquery事件_Jquery_Html_Css - Fatal编程技术网

如何正确设置“响应”jquery事件

如何正确设置“响应”jquery事件,jquery,html,css,Jquery,Html,Css,我建立了一个小函数来解释高度不同的物体网格的均匀叠加。问题是,我的jquery在移动/堆叠布局上是不必要的,而且有问题 据我所知,我正确地使用了它,但它不起作用 有什么帮助吗 在桌面>480上,else下的命令也会触发,而不仅仅是if下的命令 Codepen here:为什么不使用else而不是else if?与@bencripps所说的一样,如果显示为480px,例如:WP8,则什么都不做。你应该使用if…否则。。。 $(document).ready(function() { if (

我建立了一个小函数来解释高度不同的物体网格的均匀叠加。问题是,我的jquery在移动/堆叠布局上是不必要的,而且有问题

据我所知,我正确地使用了它,但它不起作用

有什么帮助吗

在桌面>480上,else下的命令也会触发,而不仅仅是if下的命令


Codepen here:

为什么不使用else而不是else if?与@bencripps所说的一样,如果显示为480px,例如:WP8,则什么都不做。你应该使用if…否则。。。
$(document).ready(function() {
  if ( $(window).width() < 480) {     

    // Get an array of all element heights
    var elementHeights = $('.box').map(function() {
    return $(this).height();
    }).get();

    // Math.max takes a variable number of arguments
    // `apply` is equivalent to passing each height as an argument
    var maxHeight = Math.max.apply(null, elementHeights);

    // Set each height to the max height
    $('.box').height(maxHeight);

}
else if ( $(window).width() > 480) {

    $('.box').css("height", "auto");

}

});