Get the App
SLTechnology News&Howtos  ›  Development  › 

How to set font size with javascript

Shulou Source: shulou.com Published: 2022-06-02 23:29:25 09月30日 Update

This article mainly explains "how to use javascript to set font size", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to use javascript to set font size" bar!

Javascript set font size method: 1, create "function setFontSize (id,content,params) {...}" method; 2, through "setFontSize (id,contentid, {...})" method debugging.

This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.

How does javascript set the font size?

The method of controlling font size setting by JavaScript

When working on the company's official website, the inside page of the news will have a feature that allows the viewer to resize the text, so sort out this function in this free time:

Function setFontSize (id,content,params) {var oTarget = document.getElementById (id), content = document.getElementById (content), size = params.size | | 14, maxSize = params.maxSize | | 20, step = params.step | | 2; oBtn =''; oBtn1 = null, oBtn2 = null; oTarge [XSS _ clean] = oBtn; oBtn1 = oTarget.childNodes [0] OBtn2 = oTarget.childNodes [1]; oBtn1.onclick=function () {if (size+step = 12) {size-=step;} else {size = 12; this.className+=' disabled' this.disabled = true;} oBtn1.className.replace ('disabled',''); oBtn1.disabled = false Content.style.fontSize = size + 'px';}}

Call method:

SetFontSize (id,contentid, {size:,maxSize,step:}); / * * id: the id used to store the parent box that adds or decreases two buttons. * contentid: the id where the content is stored. * {} an object that provides set parameters. |-szie: font start size (default). |-maxSize: the largest font. |-step: the step size of growth. , /

Tip: you can hide the value of the Input element through font-size:0, and then customize the style of the button.

Thank you for your reading, the above is the content of "how to set font size with javascript". After the study of this article, I believe you have a deeper understanding of how to use javascript to set font size, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Size font method content learning function button way maximum two element company inner page parameter can pass object that is train of thought situation text Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker MariaDB OPPO Reno Apple