How to move a <div> in firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hitsmly
    New Member
    • Jul 2006
    • 1

    How to move a <div> in firefox

    Hi All!

    I used the following code to move a <div> in IE browser to the position of the mouse when I click on a link

    +div tag is:
    [HTML]<div id=fm style="position :absolute; width:100px; height:100px; background:red" >moving</div>
    [/HTML]
    and javascript code is:

    ...
    [CODE=javascript]if (navigator.appN ame=="Microsoft Internet Explorer")
    {
    eval("fm.style. pixelTop=" +event.clientY) ;
    eval("fm.style. pixelLeft=" + event.clientX);
    }
    else // for firefox
    {

    }
    [/CODE]...

    for firefox, eval is invalid!!!! :(

    How to move div tag in firefox! Please help!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    1. No need to use eval here
    2. No need for browser detection, check for the support of objects instead, e.g. if (elem.style.pix elTop) {...
    3. pixelTop is only supported in IE, use top/left for other browsers.
    4. You can't access an element by its id by just using the id as a variable, use document.getEle mentById("fm") to access the element. IE's behaviour here is incorrect.
    5. The global event is only supported in IE. You need to use the event as an argument in other browsers. See link.
    6. To get the current mouse position across all browsers, clientX/Y will not do the job alone. You need a cross-browser script - link.

    Comment

    Working...