试图抓住窗口高度 - 设置像素和style.height到div

时间:2017-09-29 22:31:01

标签: javascript jquery css settimeout

我正在尝试,在一段时间后,抓住窗口的高度,然后将现有DIV的高度设置为当前高度减去顶部的菜单栏(148px)。我成功获得了高度,但是DIV style.height没有设置为新的计算高度。事件触发前DIV的高度为170px。

JS

setTimeout(function() {
    var currentHeight = $(window).height() - 148;
    console.log('before ' + currentHeight);
    fullContractorSection.style.height = "'"+currentHeight+"px'";
    var full = $(fullContractorSection).height();
    console.log('after ' + full);
}, 100);

控制台

before 568
after 170

0 个答案:

没有答案