2017-05-26 55 views
-1

是否有任何解決方案可以相對於舊的線高度值更改線高度並減少或增加它?相對於舊的線高度值更改線高度屬性

(我的目標是增加或web視圖Android中減少行高度,但我知道我可以用一些CSS或JavaScript做這樣的問題標籤是JavaScript和CSS)。

+0

例如行高度被設定爲12像素和我想通過10(22,32,42,...) –

+0

@mohammadhoseinabedini我有以下回答以增加它10 。 –

+0

@torazaburo只有當沒有單位被指定爲'line-height'時纔是如此。長度單位可以被指定。 –

回答

2

嗯,是的。

// Get a reference to the element to be changed 
 
var theP = document.querySelector("p"); 
 

 
// Set up a click event handler for the button 
 
document.querySelector("button").addEventListener("click", function(){ 
 

 
    // Get the numeric portion of the current line-height property 
 
    var h = parseInt(window.getComputedStyle(theP, null).lineHeight); 
 
    
 
    // Set the new value to twice the old value and add the unit back on to the string 
 
    theP.style.lineHeight = (h * 2) + "px"; 
 
});
p { line-height:10px; }
<button>Double the line height</button> 
 
<p>The quick brown fox jumped over the lazy dog.<br>But, when he did, the dog bit his tail</p>

+0

我想這樣做沒有任何按鈕,因爲我的按鈕是在Android中,如果你對我有利,我會向你表示謝意(原諒我因爲我的英語不好)@ScottMarcus –

+0

@mohammadhoseinabedini所以,當你想要'高度變化了嗎?如果您不想使用按鈕(或某個觸發器),只需使用'click'事件處理程序中的代碼即可。 –

+0

我有一個函數在我的android活動和一個按鈕,當我按下它調用這個函數,並用你的java腳本代碼改變行高@ScottMarcus –