Results 1 to 2 of 2

Thread: Javascript: Positionin a DIV in Mozilla

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Javascript: Positionin a DIV in Mozilla

    Here's the code I'm running to try to align some items in Mozilla:

    Code:
    function setupDIVs() {
        var objMenu = findDom('menubar');
    
        objMenu.style.left = findLeft('logobar') + 10;
        objMenu.style.color = '#003399';
    }
    
    function findLeft(objectID) {
        if (findDom(objectID).offsetLeft) {
            return findDom(objectID).offsetLeft;
        } else if (findDom(objectID).clip.left) {
            return findDom(objectID).clip.left;
        } else {
            return 0;
        }
    }
    
    function findDom(objectID){
       if (document.all){
         return document.all(objectID);
       } else if (document.getElementById){
         return document.getElementById(objectID);
       } else if (document.layers){
         return (document.layers[objectID]);
       }
    }
    The color changing works, but the element doesn't move.

    Any ideas?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I assume that position is absolute to begin with, right?

    A very likely reason for the failure is units. offsetLeft is simply a number, but style.clip.left might be a string containing a number and a unit (px, em, %, ...). If so, "addition" of 10 becomes a string concatenation and the result could be something like "40px10", which of course is an invalid value for the left style.

    Another possibility is that the calculation results in a proper number, but then you still have no unit (e.g. "50"). In full or partial standards mode (meaning that you have a DOCTYPE declaration with HTML 4 or any XHTML) Mozilla might well refuse this non-standard property value as the CSS spec requires a unit for non-0 values.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width