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

Drag-scrolling while mouse outside div #78

Open
andrewkouri opened this issue Dec 18, 2014 · 5 comments
Open

Drag-scrolling while mouse outside div #78

andrewkouri opened this issue Dec 18, 2014 · 5 comments

Comments

@andrewkouri
Copy link

I'm trying to figure out how to extend this plugin so that if the user starts scrolling in the div and then they scroll so far that the mouse ends up outside of the div, it can keep scrolling. Basically, I don't want to release control of the scrollable element when the mouse leaves the boundaries of the div. Google maps is a good example, where you can click-drag to scroll anywhere in the big map, but if you happen to move your mouse outside the map div, or even the browser window itself, it continues to scroll

@davetayls
Copy link
Owner

It would probably be a case of attaching the mouse move listeners to the window instead of the wrapper, then it will keep firing even after the mouse has left the wrapper

@andrewkouri
Copy link
Author

Would you mind putting some example code on the docs as to how to do this? I looked in the source and the passable options didn't have a mouse move listener.

@andrewkouri
Copy link
Author

(I guess it's also worth noting that I only want scrolling to happen if the click starts in the target div, but I DO want to be able continue moving if the mouse exits)

@UziTech
Copy link
Collaborator

UziTech commented Jun 24, 2015

I did this by overlaying a fixed div over the entire window and appending it to the target so any mouse moves will move the container.

This works by adding a method called startedMoving to be called whenever the threshold is reached.

I submitted a pull request with this and other useful events.

    $("div").kinetic({
        startedMoving: function (target) {
            var self = this;
            var $overlay = $("<div class='kinetic-overlay'/>").css({
                "user-select": "none",
                position: "fixed",
                top: 0,
                left: 0,
                width: "100%",
                height: "100%"
            }).mousemove(function () {
                //fixes mouse up outside browser
                if (!self.mouseDown) {
                    $(".kinetic-overlay").remove();
                }
            });
            $(target).append($overlay);
        }
    });

@ConeyIsland
Copy link

No need in (target), works good with

$(self.$el).append($overlay);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants