繁体   English   中英

$(window).resize()不会触发函数

[英]$(window).resize() doesn't fire function

我写了一个函数,它应该在页面首次加载时以及用户调整窗口大小时触发。 它在页面加载时工作正常,但在用户调整窗口大小时不起作用。 奇怪的是,如果我在函数内部发出警报,那么当窗口调整大小时会出现该警报,但该函数的其余部分不会触发。 我在Chrome的控制台中没有看到任何错误。 我已经尝试将其更改为$(document).resize()$("body").resize()$(".pricingHeader").resize() ,并且没有任何工作。 这对我来说毫无意义。

function getTallest() {
    var tallest = 0;
    $(".pricingHeader").not(".features .pricingHeader").each(function(){
       tallest = $(this).height() > tallest?$(this).height():tallest;
    });
    $(".pricingHeader").not(".features .pricingHeader").height(tallest);
    $(".features .pricingHeader").height(tallest + 8);
}
$(document).ready(function() {
    getTallest();
});
$(window).resize(function() {
    getTallest();
});

试试:

function getTallest() {
    var tallest = 0;
    $(".pricingHeader").not(".features .pricingHeader").each(function(i, elem){
       if ( $(elem).height() > tallest ) tallest = $(elem).height();
    });
    $(".pricingHeader").height(function() {
        var add = $(this).closest('.features').length ? 8 : 0;
        return tallest+add;
    });
}

$(function() {
    $(window).on('resize', getTallest).trigger('resize');
});

好吧,我弄清楚问题是什么。 我将每个.pricingHeader的高度设置为固定高度,这阻止了最高的窗口调整大小。 这是固定的脚本:

function getTallest() {
    var tallest = 0;
    $(".pricingHeader").not(".features .pricingHeader").each(function(){
        $(this).css({height:"auto"});
        tallest = $(this).height() > tallest?$(this).height():tallest;
    });
    $(".pricingHeader").each(function() {
        $(".pricingHeader").not(".features .pricingHeader").height(tallest);
        $(".features .pricingHeader").height(tallest + 8);
    });
}
$(document).ready(function() {
    getTallest();
});
$(window).resize(function() {
    getTallest();
});

暂无
暂无

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

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