For this code to go to your Web page you must use the pixel size font (PX) instead of the relative size of the font, using "EM" or "%". Of course, if you use other font units of code can easily adapt to these. If the script cannot find the font size of a paragraph, it defaults to 12px.
Core code:
Copy Code code as follows:
var min=8;
var max=18;
function Increasefontsize () {
var p = document.getelementsbytagname (' P ');
for (i=0;i<p.length;i++) {
if (p[i].style.fontsize) {
var s = parseint (P[i].style.fontsize.replace ("px", ""));
} else {
var s = 12;
}
if (S!=max) {
s + + 1;
}
P[i].style.fontsize = s+ "px"
}
}
function Decreasefontsize () {
var p = document.getelementsbytagname (' P ');
for (i=0;i<p.length;i++) {
if (p[i].style.fontsize) {
var s = parseint (P[i].style.fontsize.replace ("px", ""));
} else {
var s = 12;
}
if (s!=min) {
S-= 1;
}
P[i].style.fontsize = s+ "px"
}
}
Include the above code in your Web page (either placed in the header section, or place it in an external JS file and import). You can then invoke the ability to increase and decrease the font size like the following.
How to use:
Copy Code code as follows:
<a href= "javascript:decreasefontsize ();" >-</a>
<a href= "javascript:increasefontsize ();" >+</a>