I have a page full of draggable items (only in horizontal).
If I open my page on a touch device I can't scroll the page down, obviously because the page is full of draggable elements. How can I make the page scrollable again?
Here's the draggable() code I'm using:
$('li').draggable({
axis: 'x',
drag: function( event, ui ) {
if(ui.position.left > 0)
ui.position.left = 0;
if(ui.position.left < -250)
ui.position.left = -250;
}
});
Just in case someone needs this:
The problem can be solved by using the "handle" option of draggable(). For example, if I have a div with a width of 500px, I can insert another (transparent) div inside it aligned to the right (for example) and with a width of 250px. Then I set this last div as the handle of the draggable div.
Using a handle is the obvious choice, but in some instances it's not a option.
In my scenario I had an inbox list whose items that you could drag to the left or right to expose action buttons. The entire inbox item must be draggable -- employing a drag handle would be unintuitive.
jQuery's
draggable
prevents vertical scrolling on touch screens if the touch was initiated inside adraggable
element. So if the screen was filled with draggable inbox items, then the user would become trapped -- unable to scroll up or down.The solution that worked for me was to measure any change in the cursor's vertical position and use
window.scrollBy
to manually scroll the window by the same amount:This will closely mimic native scrolling on a touch device.