Utilisation de JavaScript pour modifier la taille de Police de page Web

Dans ce court tutorial JavaScript, Nurani vous guide comment utiliser JavaScript en changeant la taille de police de la page Web Peut-


Sampled by © JavaScriptBank.com

Actually, almost all browsers have a feature to control the characters on the web pages you visit, by pressing the Ctrl key together with + (to zoom in) or - (to zoom out). But there is one other way of adding such a function "dynamic font size" on your site using javascript.

Here is a script that can be used to facilitate the visitors to control the font size of text on each page of your website/blog. This will be very useful for readers who struggle with small letters, and allow the person to enlarge the font size of your writing, so they are easier to read.

<script type="text/javascript">
var min=8;
var max=18;
function zoominLetter() {
   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 zoomoutLetter() {
   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"
   }
}
</script>

The script above will change the font size of text within the paragraph (tag <p>). If you want to use another tag, you can change the getElementsByTagName('p');

Of course, this script only works on the page with pixel sized fonts (letter-sized pixels (px)) compared with relative sized fonts (the relative size of the letters like: "em" and "%"). In addition, if the script does not find the font size of a paragraph, it will use the standard size, which is 12px.

How To Use :

Enter the above script on your blog page (either by typing in the tag <head> or by using .js file external and import). To call the function zoominLetter and zoomoutLetter you can use the following HTML code:

<a href="javascript:zoominLetter();">A</a>
<a href="javascript:zoomoutLetter();">a</a>

tips: You can change the text A | a with other signs, or replace it with a picture by using tags <img>.

Langue
Translate this page to English Translate this page to French Translate this page to Vietnamese

Articles r�cents
Insights for Advanced Zooming and Panning in JavaScript Charts
How to open a car sharing service
Vue developer as a vital part of every software team
Vue.js developers: hire them, use them and get ahead of the competition
3 Reasons Why Java is so Popular
Migrate to Angular: why and how you should do it
The Possible Working Methods of Python Ideology
JavaScript Research Paper: 6 Writing Tips to Craft a Masterpiece
Learning How to Make Use of New Marketing Trends
5 Important Elements of an E-commerce Website


Voir les articles Top
Ajout de JavaScript pour WordPress efficacement avec JavaScript Localisation fonction
"sentences":[{"trans":"Top 10 Beautiful Christmas Countdown Timers","orig":"Top 10 Beautiful Christm
Top 10 Best eBooks JavaScript que les débutants devraient apprendre
65 Free JavaScript Galerie de photos
16 Syntaxe du code libre par Surligneurs Javascript pour une meilleure programmation
Best Free Linux Web Programming Editors
Top 50 Most Addictive et jeux Populaire mini Facebook
Plus de 30 excellentes galeries de photo
Top 10 Free Web Chat bo
Le JavaScript Ultimate Design Tutorial dans le Web


Free JavaScript Tutorials & Articles
at www.JavaScriptBank.com