MrFish Posted October 3, 2009 Report Share Posted October 3, 2009 I've made a drop down menu that uses offsetLeft and offsetTop to position the dropdown menu. It works in Firefox and Safari but not Opera or Chrome (haven't tried IE yet because it's got other problems). In chrome and opera, offsetLeft works fine, but offsetTop does not.Right:Wrong:Code: function displaymenu(){ button = document.getElementById("menubutton"); left = button.offsetLeft + "px"; top = button.offsetTop; top = top + 25 + "px"; menu = document.getElementById("menudropdown").style; menu.top = top; menu.left = left; menu.visibility = "visible";} Link to comment Share on other sites More sharing options...
justsomeguy Posted October 3, 2009 Report Share Posted October 3, 2009 Try this:top = (top + 25) + "px"; Link to comment Share on other sites More sharing options...
MrFish Posted October 4, 2009 Author Report Share Posted October 4, 2009 Wow, thanks so much! I don't know why that made a difference. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 4, 2009 Report Share Posted October 4, 2009 The plus operator goes right-to-left, so when it saw this:top = top + 25 + "px";it did this:top = (top + (25 + "px"));So it was adding 100 to "25px", which made it "10025px"; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now