Re: scrollIntoView for XML documents

Martin Honnen <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xml
Organization Liberty Development
Message-ID <[email protected]>

Martin Honnen wrote:


> Opera 8.00 beta seems to expose those properties to XML elements so I 
> have a simple test case with Opera 8.00 beta where you can do
> 
>     function getPageCoords (element) {
>       var coords = null;
>       if (typeof element.offsetLeft != 'undefined') {
>         coords = { x: 0, y: 0 };
>         while (element) {
>           coords.x += element.offsetLeft;
>           coords.y += element.offsetTop;
>           element = element.offsetParent;
>         }
>       }
>       return coords;
>     }
> 
>     function scrollElementIntoView (element) {
>       /* desirable but does not work
>       if (typeof element.scrollIntoView != 'undefined') {
>         element.scrollIntoView(true);
>       }
>       */
>       var pageCoords = getPageCoords(element);
>       if (pageCoords) {
>         window.scrollTo(pageCoords.x, pageCoords.y);
>       }
>     }
> 
> The coordinates are not precise it seems as the scroll position seems a 
> bit wrong but the properties are there.

My bad, with Opera 8.00 beta the properties offset* and window.scrollTo 
to it works correctly, my earlier test case had a problem.

Boris, if you are reading, would it be difficult the expose 
offsetLeft/Top/Parent on arbitrary XML elements rendered in a window or 
frame with Mozilla?

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.