[thelist] Help modify a JS

miinx lists at miinx.com.au
Mon Oct 21 10:41:01 CDT 2002


Le Sauvage wrote:
> Hi, Karen,
>
> Thanks very much for your prompt response.

No problem Kris, and thanks for thanking me  :)

I am going bonkers. I am afraid it
> still does not work -- not on IE (I am using v5.5 SP2), and neither on Netscape
> (v7.0), of course. I have changed the positive and greater than signs to
> negative and lesser than signs before, actually. Would you like to take a shot
> at it again, please? I would be very grateful.

Sure thing.  There were a couple of other probs with the code,
specifically with the moveImage() function.  Here's the original:

function moveImage() {
   if(!document.all) document.all = document;
   if(!document.all.mi.style) document.all.mi.style = document.all.mi;
   divStyle = document.all.mi.style;
   currentX = startX;
   currentY = startY;
   setPosition(currentX, currentY);
   divStyle.visibility = "visible";
   setInterval("moveDiv()",movePeriod);
}

Your probs are all in the first 3 lines with the doc.all references.
That DOM is specific to IE4, and while it should work in IE5 (I think..)
  it won't work at all in NS.  Additionally, the logic is off...

This line:

   if(!document.all) document.all = document;

says "if document.all is not supported, then set document.all to equal
document" ... but if it's not supported, then we can't set it!  So that
one should be:

   if(document.all) document.all = document;

with the not operator (!) removed.

The next 2 lines I just cannot wrap my head around at the moment at all!
  Using IE4's DOM, they're trying to set a reference to the style of the
div object to the div object itself, then immediately go on to try and
grab the div style anyway...  it's quite late here, and I never really
got into the doc.all object model, so I just plain can't figure this.
(maybe someone else can explain this bit..?)

Despite my confusion, what I can say is that it won't work in NS.  So,
to get the code working there, I changed those 3 lines to:

   if (document.getElementById)
      divStyle = document.getElementById("mi").style;
   else if (document.all) {
      document.all = document;
      document.all.mi.style = document.all.mi;
      divStyle = document.all.mi.style;
   }

So, your function moveImage() now becomes:

    function moveImage() {
       if (document.getElementById)
          divStyle = document.getElementById("mi").style;
       else if (document.all) {
          document.all = document;
          document.all.mi.style = document.all.mi;
          divStyle = document.all.mi.style;
       }
       currentX = startX;
       currentY = startY;
       setPosition(currentX, currentY);
       divStyle.visibility = "visible";
       setInterval("moveDiv()",movePeriod);
    }

Add that to the previous changes, and your code will now work in NS6+
and IE5+ (have tested them m'self).

> Thanks again.

You're most welcome.  :)

cheers,
Karen
-------
Miinx Design & Development
e :: karen at miinx.com.au
p :: 0413.880.302
w :: www.miinx.com.au





More information about the thelist mailing list