SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    text resize reset button solution

    hey, got this script for changing the text size on my website and I'd like to call a function that is called resetFontSize or something similar, that simply resets the text size to its original (12px).
    The code for the incr and decr size:

    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"
    }
    }

    function resetFontSize() {

    created this one myself dunno what to put here to make it work
    }

    ----------------------
    And then I got links to call the functions on my site, like this one.

    <a href="javascript:decreaseFontSize();"><img title="Decrease size" src="images/minus.gif" alt="Decrease size" /></a>

    would be pleased for a solution.

    kind regards /jacob

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Location
    Rosario, Argentina
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this (untested):

    function resetFontSize() {
    var p = document.getElementsByTagName('p');
    for(i=0;i<p.length;i++) {
    p[i].style.fontSize = "12px"
    }
    }

  3. #3
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    works like a charm! I owe you man! thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •