2017-08-14 56 views
0

從來就寫了這個代碼來獲得一個動態的保證金爲喚起注意我的頭是:jQuery的 - 用計算+變量的函數來更改CSS

$(window).on("resize", function() { 
    var divHeight = $('#header').innerHeight(); 
    $('body > .container').css('padding-top', divHeight + 'px'); 
    }).resize(); 

現在我想給一些其他的元素相同的變量,f.ex.我的導航,但CSS的高度必須是:

height: calc(100% - 'VARIABLE FROM CODE ABOVE'); 

你有什麼建議,我怎麼能得到這個工作?
感謝所有誰讀這:)

+0

爲什麼不能以同樣的方式再次訪問它? 'var headerHeight = $('#header')。innerHeight();' – Airwavezx

+0

我想這樣做,但我不知道如何寫它,我試過這個: $('#header').css ('height',calc(divHeight +'px)'); – morizvonlanga

+0

你想再次訪問什麼變量?你想要做什麼?對我來說不是很清楚。 – Airwavezx

回答

0

我找到了一個解決方案:

$(window).on("resize", function() { 
    var divHeight = $('#header').innerHeight(); 
    $('body > .container').css('padding-top', divHeight + 'px'); 
    $('#navigation').css('margin-top', divHeight + 'px'); 
    $('#navigation').css('height', 'calc(100% - ' + divHeight + 'px)') 
    }).resize();