/*
Increase or reduce the font size on the page. To restore the original size
you need to define three elements in the html page
The classes of the elements are resetFont, increaseFont, and decreaseFont
In the JQuery event of this file, click events of the three elements are defined respectively to achieve the increase. Large, reduce, restore original size
*/
$(function () {
//Get the font size, font-size is defined under the html tag
var originalFontSize = $("html" ).css("font-size");
//Restore the default font size
$(".resetFont").click(function () {
$("html").css(" font-size", originalFontSize);
//JavaScript is not executed downwards
return false;
});
//Increase the font, and the class of an element is defined as increaseFont
$(".increaseFont").click(function () {
//Get the current font size suffix px,pt,pc
var currentFontSize = $("html").css("font- size");
//Get the current font size, convert parseFloat() to float type and remove the suffix
var currentFontSizeNumber = parseFloat(currentFontSize);
//Newly defined font size
var newFontSize = currentFontSizeNumber * 1.1;
//Rewrite the style sheet
$("html").css("font-size", newFontSize);
//JavaScript does not execute downwards
return false;
});
//Decrease the font, the class of an element is defined as decreaseFont
$(".decreaseFont").click(function () {
//Get the current Font size suffix px, pt, pc
var currentFontSize = $("html").css("font-size");
//Get the current font size, parseFloat() converts to float type to remove the suffix
var currentFontSizeNumber = parseFloat(currentFontSize);
//Redefine font size
var newFontSize = currentFontSizeNumber * 0.9;
//Rewrite style sheet
$("html").css( "font-size", newFontSize);
//JavaScript is not executed downwards
return false;
});
});
Change web fonts in real time Size, jQuery version
changes the font size of the web page in a timely manner, introduces jQuery, and adds restrictions on the maximum number of digits that can be enlarged or the minimum number of times that the font can be reduced, to avoid some meaningless functions, when the font size reaches the specified value , clicking the zoom out function again does not work. This seems to be more user-friendly.
If you need to introduce external Js, you need to refresh to execute ]