[thelist] Netscape/Mozilla js problem

Peter-Paul Koch gassinaumasis at hotmail.com
Tue Mar 25 05:08:57 CST 2003



>I use the following code to as part of a page that allows divs to be 
>dragged around. The page works in IE6, but not in NN7/Mozilla. I get an 
>error at: "topCoord = parseInt(e.target.style.top);" which says that 
>e.target.style has no properties. I'm stuck as to what to do next?
>Any help greatly appreciated.

I think it's because the target is a text node instead of the element you 
want to drag. Stupid things always creep up at the worst possible places.

>
>Code:
>
>//function to get mouse position while dragging
>function dragIt(e){
>         duringdrag = true;
>         if (!e) var e = window.event;
>//check for IE or Netscape mouse position
>         if (e.pageX || e.pageY){
>   posx = e.pageX;
>  } else if (e.clientX || e.clientY){
>   posx = e.clientX + document.body.scrollLeft;
>   posy = e.clientY + document.body.scrollTop;
>  }
>//check for IE or Netscape event target

var tg = (e.target) ? e.target : e.srcElement;
if (tg.nodeType) {
  while (tg.nodeType == 3)
    tg = tg.parentNode;
}

and use tg to calculate the position.

--------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.xs4all.nl/~ppk/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
W3C DOM Compatibility Table, expanded & updated
http://www.xs4all.nl/~ppk/js/index.html?version5.html
--------------------------------------------------


_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail



More information about the thelist mailing list