Home > Web Front-end > JS Tutorial > JQuery implementation code to change page font size (change web page font size in real time)_jquery

JQuery implementation code to change page font size (change web page font size in real time)_jquery

WBOY
Release: 2016-05-16 17:55:37
Original
1444 people have browsed it
Copy code The code is as follows:

/*
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.

[Ctrl A select all Note:
If you need to introduce external Js, you need to refresh to execute ]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template