Scaling images in IE

Discussion in 'Javascript' started by Ron Crump, Sep 22, 2003.

  1. Ron Crump

    Ron Crump Guest

    Hi,

    I have a small javascript (scalegr.js) that re-scales a sequence of
    images on a page to be less than the frame width, thus:

    function scalegr(a) {
    var imgs = document.images;
    var fw = window.innerWidth;
    for (var i=0; i<imgs.length; i++) {
    var w=imgs.width;
    imgs.width = a*fw
    }
    }

    Which is called from an HTML page as follows:

    <HTML>
    <HEAD>
    <TITLE> Test Image Scaling</TITLE>
    <script type='text/javascript' src='scalegr.js'></script>
    </HEAD>
    <body onload="javascript:{if(parent.frames[0]&&parent.frames['navbar'].Go)parent.frames['navbar'].Go();scalegr(0.85)}"
    onresize="javascript:{scalegr(0.85)}">
    <H1>Image</H1>
    <IMG SRC="trend1.gif" BORDER="0">
    </BODY>
    </HTML>

    This works fine in Netscape/Mozilla but in IE, the images appear to
    load (ie they are visible until loading completes) then they
    disappear.

    Any suggestions gratefully received, fixes to the above or a general
    way of scaling my simple images to account for people with different
    resolutions and/or not maximised browser displays.

    Could you copy replies to my e-mail too, please (rcrump at une dot edu
    dot au).

    TIA.

    Ron Crump
    Ron Crump, Sep 22, 2003
    #1
    1. Advertising

  2. Ron Crump wrote:

    > Hi,
    >
    > I have a small javascript (scalegr.js) that re-scales a sequence of
    > images on a page to be less than the frame width, thus:
    >
    > function scalegr(a) {
    > var imgs = document.images;
    > var fw = window.innerWidth;
    > for (var i=0; i<imgs.length; i++) {
    > var w=imgs.width;
    > imgs.width = a*fw
    > }
    > }
    >
    > Which is called from an HTML page as follows:
    >
    > <HTML>
    > <HEAD>
    > <TITLE> Test Image Scaling</TITLE>
    > <script type='text/javascript' src='scalegr.js'></script>
    > </HEAD>
    > <body onload="javascript:{if(parent.frames[0]&&parent.frames['navbar'].Go)parent.frames['navbar'].Go();scalegr(0.85)}"
    > onresize="javascript:{scalegr(0.85)}">
    > <H1>Image</H1>
    > <IMG SRC="trend1.gif" BORDER="0">
    > </BODY>
    > </HTML>
    >
    > This works fine in Netscape/Mozilla but in IE, the images appear to
    > load (ie they are visible until loading completes) then they
    > disappear.
    >
    > Any suggestions gratefully received, fixes to the above or a general
    > way of scaling my simple images to account for people with different
    > resolutions and/or not maximised browser displays.


    The problem is that you use
    window.innerWidth
    which doesn't exist in IE's object model, there the property is
    undefined. Thus you need
    var fw;
    if (typeof window.innerWidth != 'undefined')
    fw = window.innerWidth;
    }
    else if (document.body && document.body.clientWidth)
    fw = document.body.clientWidth

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 22, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?REVXcmlnaHRfQ0E=?=

    Control Scaling???

    =?Utf-8?B?REVXcmlnaHRfQ0E=?=, Apr 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    330
    Steven Cheng[MSFT]
    Apr 27, 2005
  2. =?Utf-8?B?REVXcmlnaHRfQ0E=?=

    Control Scaling???

    =?Utf-8?B?REVXcmlnaHRfQ0E=?=, Apr 26, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    404
    Steven Cheng[MSFT]
    Apr 28, 2005
  3. =?Utf-8?B?REVXcmlnaHRfQ0E=?=

    Page & Control Scaling?

    =?Utf-8?B?REVXcmlnaHRfQ0E=?=, May 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    366
    Steven Cheng[MSFT]
    May 26, 2005
  4. AndrewF
    Replies:
    1
    Views:
    773
    Bruce Barker
    Oct 10, 2005
  5. Rob

    SCALING IMAGES

    Rob, Nov 12, 2004, in forum: HTML
    Replies:
    7
    Views:
    579
    neredbojias
    Nov 20, 2004
Loading...

Share This Page