Results 1 to 7 of 7

Thread: MM_swapImage and Safari

  1. #1
    Join Date
    Apr 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MM_swapImage and Safari

    Hi,
    I've used the MM_SwapImage function from Dreamweaver to make a roll over gallery for a photography website. The only problem is when I use safari it changes the aspect ratio of the images.

    Here's the link:
    http://www.lizethsantos.com/fineart/.../abstract.html

    Any solutions?
    Thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Not sure on how to solve this, but I will say that it's the same here for me. It starts off ok, but then I go over one that is a different size and they all start conforming to that size. Someone should have an answer soon.
    I suggest, though, that you should look at dynamically changing the size of the image in addition to changing the src, if you have not already done so.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have fooled around a bit but am unable to really understand the function (since I'm pretty new to javascript). I could really use an experienced coder to comment the code for me! Then maybe I could make some headway on my own.

    The Main function:

    function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }

    which calls

    function MM_findObj(n, d) { //v4.01
    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

  4. #4
    Join Date
    Feb 2007
    Location
    England
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Comments

    I'm not sure if I understand, so take this with a pinch of salt

    But basically the swapimage function allows lots of arguments to be passed at once and tries to swap all the srcs of the images.

    findObj seems to go through browser checks and tries to find the object and then returns it to the swapImage function

    Code:
    function MM_swapImage() { //v3.0
    var i, j=0, x, //Initiating variables (Making them available for this function only as initiated with var)
    a=MM_swapImage.arguments; //Even the the brackets () are empty, arguments can still be passed to this function. they are stored in variable a. 
    
    document.MM_sr=new Array; //create new array named MM_sr (As a child of the document)
    
    for(i=0;i<(a.length-2);i+=3) //for all arguments passed -2,
    if ((x=MM_findObj(a[i]))!=null) //if the object exists
    {
    document.MM_sr[j++]=x;  //add it to the array
    if(!x.oSrc) x.oSrc=x.src;   //if the object doesn't have an attribute oSrc, make oSrc = the current src
    x.src=a[i+2]; //the source = array element [i+2]
    }
    }
    
    which calls
    
    function MM_findObj(n, d) { //v4.01
    var p,i,x; //Local variables
    if(!d) d=document; //store document in the varible d, if not already there
    if((p=n.indexOf("?"))>0&&parent.frames.length) { //If ? is there (I'm guessing query string) and frames
    d=parent.frames[n.substring(p+1)].document; //d = this frames document?
    n=n.substring(0,p);} // n = the string up to p
    if(!(x=d[n])&&d.all) x=d.all[n];//if not x is an object and the document allows document.all (Old IE versions), x = the object 
    for (i=0;!x&&i<d.forms.length;i++) // when x is not found and i is then than the number of forms
    x=d.forms[i][n]; //x = the forms object
    for(i=0;!x&&d.layers&&i<d.layers.length;i++)// for all layers (Netscape browsers) x=MM_findObj(n,d.layers[i].document); //find x in layers
    if(!x && d.getElementById) x=d.getElementById(n);// if get element by id, get x (New browsers)
    return x; //obvious
    }

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you explcitly assign a height and width to each image using CSS, this shouldn't happen. The script never explicitly changes the image sizes, so it shouldn't be overridden.
    Last edited by Twey; 04-11-2007 at 11:26 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Apr 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the commenting - that should be a big help.

    re: image size specification:
    I haven't used CSS for a long time and I only seem to remember that you specify fonts and the like in them but I will look into it. Thanks!

  7. #7
    Join Date
    Apr 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Solved it! I replaced the MM_SwapImage function with my own much simpler one

    function swapImage(imgE1,imgSrc) {
    var imgSize=getSize(imgSrc);
    document.images[imgE1].src=imgSrc;
    var scale=292/imgSize[1];
    document.images[imgE1].height = imgSize[1]*scale;
    document.images[imgE1].width = imgSize[0]*scale;
    }

    where maximum vertical measure of the image and getSize is the following function:

    function getSize(imgSrc) {
    var myImage = new Image();
    myImage.name = imgSrc;
    myImage.src = imgSrc;
    var w=myImage.width;
    var h=myImage.height;
    return [w, h];
    }

    thanks again.

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
  •