Hi, Question: Is there a way to get the position (top / left or x / y coordinates) of any element? Goal: The goal is to have a product listing type page with a div that appears onmouseover for each item. I was thinking it would be really nice if I could have just one div at the end of the HTML, move it to where the moused over object is, and fill it with the changing information as needed. Tried: I tried just getting the left and top styles from each element, but they are null unless they have been explicitly set in my CSS, which would defeat the purpose. I thought I would throw this question out there...If there is a way to do this, awesome. If this functionality is possible, but not available now, I think this would be a great addition to scriptaculous. Thanks in advance for any time and help you can offer, Mike. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Try some of the Position.* methods. They''ll give you X and Y coordinates relative to the page (Position.cumulativeOffset), the positioning parent (Position.positionedOffset), and the viewport (Position.page). Cheers, Andrew --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
From mailing list 7-21-06 By Thomas Fuchs: This works for me, but it''s a bit ugly... :) Event.localPointer = function(event){ var p = [Event.pointerX(event), Event.pointerY(event)]; var element = arguments[1] || Event.element(event); var e = Position.page($(element)); return [ p[0]-(e[0]+(window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0)), p[1]-(e[1]+(window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0))]; }>Hi, > >Question: >Is there a way to get the position (top / left or x / y coordinates) of >any element? > >Goal: >The goal is to have a product listing type page with a div that appears >onmouseover for each item. I was thinking it would be really nice if I >could have just one div at the end of the HTML, move it to where the >moused over object is, and fill it with the changing information as >needed. > >Tried: >I tried just getting the left and top styles from each element, but >they are null unless they have been explicitly set in my CSS, which >would defeat the purpose. > >I thought I would throw this question out there...If there is a way to >do this, awesome. If this functionality is possible, but not available >now, I think this would be a great addition to scriptaculous. > >Thanks in advance for any time and help you can offer, >Mike. > >> > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
This worked for me: var x; var y; Event.observe(document, ''mousemove'', function(event){ x = Event.pointerX(event); y = Event.pointerY(event); Ian Tyndall wrote:> From mailing list 7-21-06 By Thomas Fuchs: > This works for me, but it''s a bit ugly... :) > > Event.localPointer = function(event){ > var p = [Event.pointerX(event), Event.pointerY(event)]; > var element = arguments[1] || Event.element(event); > var e = Position.page($(element)); > return [ > p[0]-(e[0]+(window.pageXOffset || > document.documentElement.scrollLeft || document.body.scrollLeft || 0)), > p[1]-(e[1]+(window.pageYOffset || > document.documentElement.scrollTop || document.body.scrollTop || 0))]; > } > > >Hi, > > > >Question: > >Is there a way to get the position (top / left or x / y coordinates) of > >any element? > > > >Goal: > >The goal is to have a product listing type page with a div that appears > >onmouseover for each item. I was thinking it would be really nice if I > >could have just one div at the end of the HTML, move it to where the > >moused over object is, and fill it with the changing information as > >needed. > > > >Tried: > >I tried just getting the left and top styles from each element, but > >they are null unless they have been explicitly set in my CSS, which > >would defeat the purpose. > > > >I thought I would throw this question out there...If there is a way to > >do this, awesome. If this functionality is possible, but not available > >now, I think this would be a great addition to scriptaculous. > > > >Thanks in advance for any time and help you can offer, > >Mike. > > > >> > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs -~----------~----~----~----~------~----~------~--~---
Just to put a conclusion on this (I almost forgot to thank you guys)... Thanks for all your help. The Position.* methods had what I needed, I had just not seen them before in the documentation, etc. Thanks again, Mike. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---