| | |
Positioning, Scrolling & FireFox
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 1
Reputation:
Solved Threads: 0
I am sure this is old hat to many of you, but it is new to me.
The idea is to display a floating menu when the mouse is over a non-positioned DIV item.
First, I get the position of the DIV item, which works fine. Then I use style.left and style.top to position the floating menu, which works fine on both IE and FireFox, except when the user scrolls the page on FireFox. When the user scrolls, the style.left and style.top seem to position in the floating menu offset by the scrolled amount.
When I try to correct the effect of FireFox scolling, neither window.pageXOffset or window.scrollX provides the amount scrolled. Both pageXOffset and scrollX are zero.
You can see this working (or not working, really) at http://www.statmatics.com/ltf.
Here are some code details. The floating menu:
Get the position of the mouseover item
Show the floating menu and position it near the item
Any ideas? Thanks for your help.
Paul Richards
Stat-Matics, Inc., Melbourne, Florida
The idea is to display a floating menu when the mouse is over a non-positioned DIV item.
First, I get the position of the DIV item, which works fine. Then I use style.left and style.top to position the floating menu, which works fine on both IE and FireFox, except when the user scrolls the page on FireFox. When the user scrolls, the style.left and style.top seem to position in the floating menu offset by the scrolled amount.
When I try to correct the effect of FireFox scolling, neither window.pageXOffset or window.scrollX provides the amount scrolled. Both pageXOffset and scrollX are zero.
You can see this working (or not working, really) at http://www.statmatics.com/ltf.
Here are some code details. The floating menu:
html Syntax (Toggle Plain Text)
<style> #menu { border:none; margin: 4px; position: absolute; } </style> <body> <div id=menu> </div> </body>
Get the position of the mouseover item
javascript Syntax (Toggle Plain Text)
var item = document.getElementById (itemId); var itemWidth = <code to get width of item> var itemHeight = <code to get height of item> var itemLeft = 0; var itemTop = 0; var offsetTrail = item; while (offsetTrail) { itemLeft += offsetTrail.offsetLeft; itemTop += offsetTrail.offsetTop; offsetTrail = offsetTrail.offsetParent;
Show the floating menu and position it near the item
javascript Syntax (Toggle Plain Text)
var menu = document.getElementById("menu"); menu.innerHTML = <HTML of the floating menu> menu.border = "1px solid brown"; var px = (typeof menu.style.left == "string") ? "px" : 0; menuLeft = Math.floor(itemLeft + 0.7*itemWidth); menuTop = Math.floor(itemTop - 0.4*itemHeight); menu.style.left = menuLeft + px; menu.style.top = menuTop + px;
Any ideas? Thanks for your help.
Paul Richards
Stat-Matics, Inc., Melbourne, Florida
Last edited by peter_budo; Apr 3rd, 2008 at 12:06 pm. Reason: Keep It Organized - please use [code] tags
Instead of looking for scroll positions relative to the document, I would read mouse's position to find out where to place the <div>. The event element do the trick, so:
event.clientX is the x position where the event occurred and
event.clientY is the Y position.
Then, the code
event.clientX is the x position where the event occurred and
event.clientY is the Y position.
Then, the code
mydiv.style.left = (event.clientX + 4) + 'px'; will set left position of "mydiv" 4 pixels right to where the mouse is pointing at. You keep going, have a Nice day!
Henry.
Before printing this message, make sure is necessary.
Henry.
Before printing this message, make sure is necessary.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: JavaScript form validation - please help
- Next Thread: Dropdown menu not working in firefox
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta blackjack boarder box captcha card cart codes column css date debugger decimal design developer dom download element embed enter error events firefox focus form frameworks getselection google gwt hiddenvalue hint html htmlform ie7 iframe image() index java javascript javascripthelp2020 javascripts jawascriptruntimeerror jquery jsp libcurl listbox maps marquee masterpage media menu microsoft mimic mp4 onerror onmouseover parameters paypal php player position post problem programming prototype rating redirect regex safari scale scriptlets search security select size software sources sql starrating textarea toggle tweet twitter unicode validation variables w3c webservice website window windowofwords xml





