Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolls when running on a touch based device #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions ngDraggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,23 +574,39 @@ angular.module("ngDraggable", [])

if (config.horizontalScroll) {
// If horizontal scrolling is active.
if (lastMouseEvent.clientX < config.activationDistance) {

// lastMouseEvent.clientX is undefined when dealing with a touch device, resulting in
// no scrolling when dragging an item to the bottom of the screen
// Seen on Chrome 47.0.2526.111
var clientX = lastMouseEvent.clientX;
if (angular.isUndefined(lastMouseEvent.clientX))
clientX = lastMouseEvent.touches[0].clientX;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

touches is not defined on event itself, it is defined on originalEvent - use lastMouseEvent.originalEvenet.touches[0]
or rather - inject ngDraggable and use ngDraggable.inputEvent(lastMouseEvent).clientY


if (clientX < config.activationDistance) {
// If the mouse is on the left of the viewport within the activation distance.
scrollX = -config.scrollDistance;
}
else if (lastMouseEvent.clientX > viewportWidth - config.activationDistance) {
else if (clientX > viewportWidth - config.activationDistance) {
// If the mouse is on the right of the viewport within the activation distance.
scrollX = config.scrollDistance;
}
}

if (config.verticalScroll) {
// If vertical scrolling is active.
if (lastMouseEvent.clientY < config.activationDistance) {

// lastMouseEvent.clientY is undefined when dealing with a touch device, resulting in
// no scrolling when dragging an item to the bottom of the screen
// Seen on Chrome 47.0.2526.111
var clientY = lastMouseEvent.clientY;
if (angular.isUndefined(lastMouseEvent.clientY))
clientY = lastMouseEvent.touches[0].clientY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

touches is not defined on event itself, it is defined on originalEvent - use lastMouseEvent.originalEvenet.touches[0]
or rather - inject ngDraggable and use ngDraggable.inputEvent(lastMouseEvent).clientY


if (clientY < config.activationDistance) {
// If the mouse is on the top of the viewport within the activation distance.
scrollY = -config.scrollDistance;
}
else if (lastMouseEvent.clientY > viewportHeight - config.activationDistance) {
else if (clientY > viewportHeight - config.activationDistance) {
// If the mouse is on the bottom of the viewport within the activation distance.
scrollY = config.scrollDistance;
}
Expand Down