2017-05-26 104 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 –