簡體   English   中英

增大/減小頁面中所有元素的字體大小

[英]Increase/Decrease font size of all elements in page in angular

我的角度組件中有一段代碼:

    IncreaseFontSize()
    {
        let FontSize:any = document.body.style.fontSize;
        if(!FontSize)
        {
            FontSize = 1.4;
        }
        else
        {
            FontSize = parseFloat(FontSize);
        }
        document.body.style.fontSize = (FontSize+0.1) + 'rem';
    }


    DecreaseFontSize()
    {
        let FontSize:any = document.body.style.fontSize;
        if(!FontSize)
        {
            FontSize = 1.4;
        }
        else
        {
            FontSize = parseFloat(FontSize);
        }
        document.body.style.fontSize = (FontSize-0.1) + 'rem';
    }

單擊兩個按鈕可調用這些功能,但不會更改已為其定義了字體大小的元素的字體大小。

我需要增加/減少所有元素的字體大小 ,即,如果標簽的字體大小為12px,段落的字體大小為11px,div的字體大小為1.2rem,則在單擊時應將其字體大小增加0.1 rem。增加按鈕。

我應該如何進行? 提前致謝。

嘗試這樣的事情。 您可以看到pxdiv不會增長,而其他的會增長。

 var fontSize = 16; function IncreaseFontSize() { fontSize = (fontSize + 1); document.body.style.fontSize = fontSize + 'px'; } function DecreaseFontSize() { fontSize = (fontSize - 1); document.body.style.fontSize = fontSize + 'px'; } 
 body, .font-constant { font-size: 16px; } .font-varies { font-size: 1em; } 
 <button onclick="IncreaseFontSize()">+</button> <button onclick="DecreaseFontSize()">-</button> <div class="font-varies"> Hello </div> <div class="font-constant"> how are you? </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM