Changing the position of HTML elements 
Author Message
 Changing the position of HTML elements

How can I obtain the original x and y coordinates of an element, as
determined by the browser, so I can
? "nudge" them a little bit?

? Looking for .style.top before setting .style.position to "absolute" or
"relative" returns an empty string.

? What I really want to do is to nudge an element over or down a few
pixels from where the browser would
? normally put it.



Fri, 07 Jun 2002 03:00:00 GMT  
 Changing the position of HTML elements


Fri, 19 Jun 1992 00:00:00 GMT  
 Changing the position of HTML elements
How can I obtain the original x and y coordinates of an element, as
determined by the browser, so I can? "nudge" them a little bit?

Looking for .style.top before setting .style.position to "absolute" or
"relative" returns an empty string.



Sat, 08 Jun 2002 03:00:00 GMT  
 Changing the position of HTML elements


Fri, 19 Jun 1992 00:00:00 GMT  
 Changing the position of HTML elements
These are right out the book, and i use them a lot  =)
hope they help

<script language="javascript">
var isNav, isIE
var coll = ""
var styleObj = ""

if (parseInt(navigator.appVersion) >= 4){
    if (navigator.appName == "Netscape"){
       isNav = true
       isIE = false
    }
    else{
       isIE = true
       isNav = false
       coll = "all."
       styleObj = ".style"
   }

 }

function getObject(obj){
 var theObj;
 if (typeof obj =="string"){
    theObj = eval("document." + coll + obj + styleObj);
 }
 else{
    theObj = obj;
 }
 return theObj

Quote:
}

function shiftTo(obj, x, y){
  var theObj = getObject(obj)
  if (isNav){
    theOjb.moveTo(x,y)
  }
  else{
    theObj.pixelLeft = x
    theObj.pixelTop = y
  }
 }

function shiftBy(obj, deltaX, deltaY){
    var theObj = getObject(obj)
    if (isNav){
      theObj.moveBy(deltaX, deltaY)
    }
    else{
      theObj.pixleLeft += deltaX
      theObj.pixleTop += deltaY
    }

Quote:
}

function getObjectLeft(obj){
  var theObj = getObject(obj)
  if (isNav){
     return theObj.left
  }
  else{
     return theObj.pixelLeft
  }

Quote:
}  

function getObjectTop(obj){
 var theObj = getObject(obj)
 if (isNav){

   return theObj.top
 }
 else{
    return theObj.pixelTop
 }

Quote:
}

<script>
Quote:
-----Original Message-----

Posted At: Monday, December 20, 1999 5:56 AM
Posted To: jscript
Conversation: Changing the position of HTML elements
Subject: Changing the position of HTML elements

How can I obtain the original x and y coordinates of an element, as
determined by the browser, so I can
? "nudge" them a little bit?

? Looking for .style.top before setting .style.position to "absolute" or
"relative" returns an empty string.

? What I really want to do is to nudge an element over or down a few
pixels from where the browser would
? normally put it.



Sat, 08 Jun 2002 03:00:00 GMT  
 Changing the position of HTML elements


Fri, 19 Jun 1992 00:00:00 GMT  
 Changing the position of HTML elements
On Tue, 21 Dec 1999 15:55:49 +0200, David Freedman

Quote:

>How can I obtain the original x and y coordinates of an element, as
>determined by the browser, so I can? "nudge" them a little bit?

Depends on what element I would think.  A <DIV> seems to work pretty
well in both NS and IE, so you could make a function and assing it to
the onresize event, so whenever the pages is resized you can move
the DIV.  First set its visibility to "hidden" change the top and left
pixel position, then change visibility back to "visible"

The problem is the different object models in NS and IE,
so you might have to do
if (navigator.appName == "Netscape") {
 do these lines

Quote:
}

else  {
do these lines

Quote:
}

so you can access the object with the correct syntax

Mike

--

"Genius gives birth, talent delivers."

           -- Jack Kerouac

(Remove NOSPAM, if present, to reply via email)



Fri, 05 Jul 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Find an HTML element at position x,y

2. HTML element property changes through scripts

3. DOM and element positioning

4. Forms elements are not displayed in positioned divs

5. Element Positioning

6. Work out the absolute position of an element

7. Finding element positions

8. Height of positioned elements in IE!!!!!!

9. Determining positions of elements

10. Cursor position in the TEXTAREA element

11. position of an XML element (XSLT)

12. position of the element

 

 
Powered by phpBB® Forum Software