Getting absolute position of an element relative to browser

ertoblivizzz

New Member
I have a div set to the css class float with float being:\[code\].float {display:block; position:fixed; top: 20px;left: 0px;z-index: 1999999999;}* html .float {position:absolute;}\[/code\]This class causes the element to stay in a fixed position on the page (the *html part is to make it work in IE). I am using javascript to shift the position of the element horizontally and vertically.I need to get the absolute position of the div relative to the browser window in javascript (how many pixels from the top and left of the browser window the div is). Right now, I am using the following:\[code\]pos_left = document.getElementById('container').offsetLeft;pos_top = document.getElementById('container').offsetTop;\[/code\]The code above works for IE, Chrome, and FF, but in Opera it returns 0 for both. I need a solution that works for all of those browsers. Any ideas?Btw: Keeping tracking of the changes made by javascript is possible, but that is not the solution I am looking for due to performance reasons. Also, I am not using jquery.
 
Top