Javascript to fix Safari image distortion bug

Ask a Question related to Macromedia Dynamic HTML, Design and Development.

  1. #1

    Default Javascript to fix Safari image distortion bug

    I have a photo page that swaps out images and captions when a thumbnail is
    clicked. The javascript is in an external file and reads as follows:

    function showPhoto (whichPhoto) {
    if (document.getElementById) {
    document.getElementById('placeholder').src = whichPhoto.href;
    if (whichPhoto.title) {
    document.getElementById('desc').childNodes[0].nodeValue = whichPhoto.title;
    }
    else {
    document.getElementById('desc').childNodes[0].nodeValue =
    whichPhoto.childNodes[0].nodeValue;
    }
    return false;
    }
    else {
    return true;
    }
    }

    There's a known bug in Safari that distorts the swapped image if either the
    width or height are the same. Someone suggested I add some script to swap a
    single-pixel image before swapping in the actual image. How do I incorporate
    that into my code?

    Also, it swaps in the captions ('desc') awkwardly in Safari. The captions are
    supposed to be centered; instead, each starts at the place where the first
    caption is positioned. Can I overcome this? If not, I can live with it.

    anubia Guest

  2. Similar Questions and Discussions

    1. CF Document Image Distortion in PDF
      We are using ColdFusion 7.0 on Windows 2003 and have employed the CFDOCUMENT tag to convert a JSP page into a PDF document. The page has several...
    2. image distortion on playback
      Hello. When I create my movie in Flash, it looks fine. When I export it and watch it, on roll out of one of the buttons, it distorts one of the...
    3. How do I get rid of image dither/distortion and make images color mode friendly?
      I have a website for which I have designed all the graphics in fireworks, and I've noticed when I view it from other peoples computers(different...
    4. Safari and layers (DIV) with a javascript.
      I have a script inserted in a layer which changes a particulair picture in that same layer every time you refresh the browser. This layer is...
    5. [Q] Safari, Javascript and sort function
      Hello, I'm looking for a script to sort a html table. On the web, I found a lot of js scripts to do that but none working with Safari. Someone...
  3. #2

    Default Re: Javascript to fix Safari image distortion bug

    > There's a known bug in Safari that distorts the swapped image if either
    > the
    > width or height are the same.
    What? Do you have a reference to this? Did you mean to say "...height are
    NOT the same."?

    --
    Murray --- ICQ 71997575
    Team Macromedia Volunteer for Dreamweaver
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    [url]http://www.dreamweavermx-templates.com[/url] - Template Triage!
    [url]http://www.projectseven.com/go[/url] - DW FAQs, Tutorials & Resources
    [url]http://www.dwfaq.com[/url] - DW FAQs, Tutorials & Resources
    [url]http://www.macromedia.com/support/search/[/url] - Macromedia (MM) Technotes
    ==================


    "anubia" <webforumsuser@macromedia.com> wrote in message
    news:do5skc$bhu$1@forums.macromedia.com...
    >I have a photo page that swaps out images and captions when a thumbnail is
    > clicked. The javascript is in an external file and reads as follows:
    >
    > function showPhoto (whichPhoto) {
    > if (document.getElementById) {
    > document.getElementById('placeholder').src = whichPhoto.href;
    > if (whichPhoto.title) {
    > document.getElementById('desc').childNodes[0].nodeValue =
    > whichPhoto.title;
    > }
    > else {
    > document.getElementById('desc').childNodes[0].nodeValue =
    > whichPhoto.childNodes[0].nodeValue;
    > }
    > return false;
    > }
    > else {
    > return true;
    > }
    > }
    >
    > There's a known bug in Safari that distorts the swapped image if either
    > the
    > width or height are the same. Someone suggested I add some script to swap
    > a
    > single-pixel image before swapping in the actual image. How do I
    > incorporate
    > that into my code?
    >
    > Also, it swaps in the captions ('desc') awkwardly in Safari. The captions
    > are
    > supposed to be centered; instead, each starts at the place where the first
    > caption is positioned. Can I overcome this? If not, I can live with it.
    >

    Murray *TMM* Guest

  4. #3

    Default Re: Javascript to fix Safari image distortion bug

    The bug report may be found here:

    [url]http://www.quirksmode.org/bugreports/archives/2005/03/Safari_Image_src_swap_resi[/url]
    ze_bug.html

    If one of the two dimensions is the same, the image distorts. Only if BOTH the
    width and height are different do the images render properly in Safari. Their
    solution was to have a single-pixel image load first before the actual image,
    thus insuring that the widths and heights would be different. I don't know how
    to shoehorn their solution into the code I have.

    anubia Guest

  5. #4

    Default Re: Javascript to fix Safari image distortion bug

    I don't believe it. I do image swaps with images that have identically
    sized dimensions and they do not distort.

    Here is what that link says -
    When swapping images with javascript Safari will stretch the new image to
    the size of the previous image, unless the previous and new images have
    different widths AND heights.

    So - are you swapping an image with one width/height with another with a
    different width/height? In that case the incoming image will *always* be
    distorted in all browsers to match the dimensions of the original image.

    If you want to swap two differently sized images, you can do this many ways
    ways -



    1. Don't use swap image - use Show/Hide layer instead. Have the alternate
    image in a hidden layer that is shown when the trigger is 'tickled'. Using
    this method you can have images that are any dimension.



    2. Use swap image, but remove the dimensions from the original image's tag,
    i.e., change this -



    <img name="original" width="150" height="220" ...



    to this -



    <img name="original" ...



    Now when you swap in your offsize image, there is no predefined size to
    change it to. Be aware that this method may well result in an unpleasant
    and undesirable 'rearrangement' of your page layout as it adjusts to your
    new image's dimensions.



    3. Pad the smaller image with canvas background color on all sides so that
    all the images *are the same size*.



    4. Use a SetTextofLayer behavior to change the image reference in a layer
    positioned so that it will show the desired larger image in the proper
    place.



    5. Use the PVII ShowPic extension - [url]http://www.projectseven.com/[/url]



    Take your pick....


    --
    Murray --- ICQ 71997575
    Team Macromedia Volunteer for Dreamweaver
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    [url]http://www.dreamweavermx-templates.com[/url] - Template Triage!
    [url]http://www.projectseven.com/go[/url] - DW FAQs, Tutorials & Resources
    [url]http://www.dwfaq.com[/url] - DW FAQs, Tutorials & Resources
    [url]http://www.macromedia.com/support/search/[/url] - Macromedia (MM) Technotes
    ==================


    "anubia" <webforumsuser@macromedia.com> wrote in message
    news:do8eo5$6la$1@forums.macromedia.com...
    > The bug report may be found here:
    >
    > [url]http://www.quirksmode.org/bugreports/archives/2005/03/Safari_Image_src_swap_resi[/url]
    > ze_bug.html
    >
    > If one of the two dimensions is the same, the image distorts. Only if BOTH
    > the
    > width and height are different do the images render properly in Safari.
    > Their
    > solution was to have a single-pixel image load first before the actual
    > image,
    > thus insuring that the widths and heights would be different. I don't know
    > how
    > to shoehorn their solution into the code I have.
    >

    Murray *TMM* Guest

  6. #5

    Default Re: Javascript to fix Safari image distortion bug

    Murray wrote:
    "So - are you swapping an image with one width/height with another with a
    different width/height? In that case the incoming image will *always* be
    distorted in all browsers to match the dimensions of the original image."

    Not so, Murray TMM. The code (which, by the way, I got from
    [url]www.alistapart.com/articles/imagegallery[/url]) works fine. Apparently the trick is
    to not set the width and height of the placeholder element. You can see it in
    action at [url]http://www.slipperypeople.com/p_cdrelease.html[/url] and
    [url]http://www.slipperypeople.com/p_berkeley04.html[/url]. It's made my life soooo much
    easier.

    It's only because of the known bug in Sarari that it doesn't behave properly.
    Quirksmode
    ([url]http://www.quirksmode.org/bugreports/archives/2005/03/Safari_Image_src_swap_res[/url]
    ize_bug.html) offers a workaround, but I don't know how to implement it into my
    existing code. Safari also does the funky caption placement. HELP.

    anubia Guest

  7. #6

    Default Re: Javascript to fix Safari image distortion bug

    Apologies. I didn't understand what you were saying. I can see what you
    are describing here -

    [url]http://www.murraytestsite.com/swapimagesizetest.html[/url]

    Note that the "home" image has no dimensions specified (it's 95px tall).
    This allows a swap with the red image to occur without distorting the red
    image. But then the restore of the original image causes it to be
    distorted.

    The solution is to make the second image NOT be 95px tall (consider 94px as
    a good compromise) - see the second link on that page for an example.

    --
    Murray --- ICQ 71997575
    Team Macromedia Volunteer for Dreamweaver
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    [url]http://www.dreamweavermx-templates.com[/url] - Template Triage!
    [url]http://www.projectseven.com/go[/url] - DW FAQs, Tutorials & Resources
    [url]http://www.dwfaq.com[/url] - DW FAQs, Tutorials & Resources
    [url]http://www.macromedia.com/support/search/[/url] - Macromedia (MM) Technotes
    ==================


    "anubia" <webforumsuser@macromedia.com> wrote in message
    news:do9kdq$3p4$1@forums.macromedia.com...
    > Murray wrote:
    > "So - are you swapping an image with one width/height with another with a
    > different width/height? In that case the incoming image will *always* be
    > distorted in all browsers to match the dimensions of the original image."
    >
    > Not so, Murray TMM. The code (which, by the way, I got from
    > [url]www.alistapart.com/articles/imagegallery[/url]) works fine. Apparently the trick
    > is
    > to not set the width and height of the placeholder element. You can see it
    > in
    > action at [url]http://www.slipperypeople.com/p_cdrelease.html[/url] and
    > [url]http://www.slipperypeople.com/p_berkeley04.html[/url]. It's made my life soooo
    > much
    > easier.
    >
    > It's only because of the known bug in Sarari that it doesn't behave
    > properly.
    > Quirksmode
    > ([url]http://www.quirksmode.org/bugreports/archives/2005/03/Safari_Image_src_swap_res[/url]
    > ize_bug.html) offers a workaround, but I don't know how to implement it
    > into my
    > existing code. Safari also does the funky caption placement. HELP.
    >

    Murray *TMM* Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139