views:

56

answers:

2

I have a simple Javascript drag function. You can see it here:

http://jsfiddle.net/XpAyA/12/

The red #dragger div is draggable. It is nested in an overflow scroll div but it doesn't trigger a "scroll" when it gets over the limit. Probably due to the fact that it is positioned absolute. Is there a way yo fix this? Make the scroll happen when it exceeds the limits? Thank you

A: 

First of all you have to give the containing div a position:relative. That way the absolutely positioned dragger stays inside of it and can't go over it's borders.

I'm not sure why the scrolling doesn't work, but is there a reason you scripted your dragging function yourself while you do have access to jQuery? There's a powerful function in jQuery called draggable that does exactly what you want.

Litso
Yes, I think that I need to have a position relative on the dragged element. Indeed there is a draggable jQuery UI function but I can not use it for this project. My draggable code have 2K while the jQuery + UI library is arround 100 KB...
Mircea
Sorry, I don't know how jquery makes the draggable object scroll.
Litso
A: 

Here's a version that scrolls http://jsfiddle.net/vcJuF/1/

I removed the inner div, which seemed to help. The scrollbars update now, I think you just need to update your javascript to actually scroll the div as you drag.

cantabilesoftware
This does the same as what I said, so it doesn't solve it either.
Litso
What browser are you using? Definitely for me in Chrome, I see the horizontal scroll bar change as I drag the red div off the right hand side (you need to drag further than the vertical scroll bar). Have I misunderstood your question? Are you talking about actually invoking the scroll of the window, or just getting the scroll bar to update. The actual scrolling I think you'll need to do in your JavaScript? Also, btw: your js doesn't work in IE8 (doesn't like .screenX).
cantabilesoftware
Yes, we talking about actually invoking the scroll not just having one appear. I see that jQuery draggable() does it well...
Mircea
"your js doesn't work in IE8" I will Google ChromeFrame this one.
Mircea
@Mircea: cool, just thought I'd mention it cause I noticed it. :)
cantabilesoftware