Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript CSS Text Resize

    I need some help.

    How exactly would I write this? I cannot get this to work.

    If screen width is less than or = 800 than change then change the CSS font-size to 10px;
    Else don't do anything.

    I would like to integrate it into the following function

    Code:
    <script language="javascript" type="text/javascript">
    function resize() {
    // Variables to be sent to PHP.  The PHP variables to be sent are in "" (ie width=, imgpath=)
     var width = "width=" + screen.width; // Set variable width to users screen width
     var path = "imgpath=images/&"; // Set the path to the image
     var logo = "imgname=scrfix-logo.png&"; //Name of my image
     var shopping = "imgname=shopping-cart.jpg&";  //Name of my image
     var forums = "imgname=forums.jpg&"; //Name of my image
     var signin = "imgname=sign-in.jpg&"; //Name of my image
     var contact = "imgname=contactus.jpg&"; //Name of my image
     var printer = "imgname=printer.jpg&"; //Name of my image
    // End of Variables to be sent to PHP.  The below variables are only for this script.
     var script = "shrink.php?"; // The name of the php script
     var scrpth = script + path; //Combine both the script and the path to make it less to work with below.
    
     // CSS Reduced Text Based Upon Width
     if(width <= 800){
      document.write('<link rel="stylesheet" type="text/css" href="../css/size.css" />');
    }
    
     document.write('<a href="/"><img border="0" class="headerimages" src="' + scrpth + logo + width + '" alt="Spectacular Computer Repair" title="Spectacular Computer Repair" /></a>');
     document.write('<a href="/catalog/"><img border="0" class="headerimages" src="' + scrpth + shopping + width + '" alt="Computer Repair Shopping" title="Computer Repair Shopping" /></a>');
     document.write('<a href="/computer-repair-forums/"><img border="0" class="headerimages" src="' + scrpth + forums + width + '" alt="Computer Repair Forums" title="Computer Repair Forums" /></a>');
     document.write('<a href="/coordinator.php"><img border="0" class="headerimages" src="' + scrpth + signin + width + '" alt="User Sign In" title="User Sign In" /></a>');
     document.write('<a href="/contact.php"><img border="0" class="headerimages" src="' + scrpth + contact + width + '" alt="Contact Spectacular Computer Repair" title="Contact Spectacular Computer Repair" /></a>');
     document.write('<a href="#" onclick="window.print();return false;"><img border="0" class="headerimages" src="' + scrpth + printer + width + '" alt="Print This Page" title="Print This Page" /></a>');
    
    return 0;
    }
    </script>
    Thanks,

    Wayne

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Try to add the higlighted:
    Code:
     if(width <= 800){
      document.write('<link rel="stylesheet" type="text/css" href="../css/size.css" /><style type="text/css">body{font-size:10pt;}</style>');
    }
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did however it cancels out at the last } because it thinks it is part of the function. It doesn't work. Also I am looking for the anchor text so it would be a { font-size:10pt; }; but every time I do it I get errors. Is there another way?

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Could you please show us your complete modification.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

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