Click to See Complete Forum and Search --> : window scrolling using drag-and-drop DIV


noothan
03-13-2003, 08:46 PM
I have a DIV object that I can move around within a browser frame. The position to "absolute", and the onmousemove event behavior then changes the x and y coordinates of the DIV. I pick up the DIV with an onmousedown event, and drop the DIV with an onmouseup event.

My problem is that when I move the DIV to the edge of the frame, it doesn't automatically scroll (I want this only when scrollbars are enabled, of course).

I've tried to force scrolling in Javascript by checking the window.frameElement.scrollLeft and window.frameElement.scrollTop properties, then using the window.scrollBy method. The scrollLeft and scrollTop properties, however, always return 0 even when the scrollbars are enabled.

Ideally, no extra Javascript would be required, if the DIV were styled correctly. Any ideas?

gil davis
03-14-2003, 05:41 AM
When you move the object, you are probably using the (x, y) mouse coordinates. These are always within the bounds of the window object. You would have to calculate where the edges of your object are in relation to the offset size of the document and use the scrollBy() or scrollTo() method to move the content in relation to the window.

You can find a helpful graphic at
http://msdn.microsoft.com/workshop/Author/om/measuring.asp