function expand(btn) {
var box = btn.parentNode.parentNode,
ipsum = box.getElementsByTagName("p")[0],
textSize = window.getComputedStyle(ipsum, null).getPropertyValue('font-size'),
lineHeight = window.getComputedStyle(ipsum, null).getPropertyValue('line-height'),
boxWidth = window.getComputedStyle(box, null).getPropertyValue('width'),
initialHeight = window.getComputedStyle(box, null).getPropertyValue('height'),
numText = parseInt(textSize),
numWidth = parseInt(boxWidth),
numHeight= parseInt(initialHeight);
if(box.style.height == "150px"){
box.style.height = "40px";
ipsum.style = "display:none";
}
else{
box.style.height = "150px";
ipsum.style = "display:inline";
}
console.log(lineHeight);
}
獲取元素的唯一問題是,元件高度頻繁變化的初始高度值,但所獲得的第一個值始終正確如何獲得初始值並保持靜態? 我如何只存儲變量中的值一次,我需要它在一個變量做計算,但隨着價值不斷變化我得到錯誤的數字輸出。
好吧,除非你一直保存高度值到該變量中,你有你的初始值在那裏..也許我錯過了一些東西,你可以詳細說明問題(請在你的問題,請不要作爲評論) – myfunkyside 2014-10-02 03:05:52