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

cancel the jump animation #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bretkikehara
Copy link

@bretkikehara bretkikehara commented Aug 25, 2016

When jump is called expose the cancel handler to stop the animation.

Tries to solve #7 without external dependencies or extra event handlers

@bretkikehara
Copy link
Author

bretkikehara commented Sep 1, 2016

btw, if anyone is interested in trying this PR...

$ npm install [email protected]
var jumper = require('jump.js-cancelable');
jumper.jump(...);
jumper.cancel();

@callmecavs
Copy link
Owner

callmecavs commented Sep 1, 2016

@bretkikehara havent had time to look closely at the changes to the source, but do think this is the best approach - no event listeners, just giving the user a function to cancel the jump as they see fit.

will take a look when I get the chance - thanks for the submission and taking the initiative on this one.

@bretkikehara
Copy link
Author

So after using this a bit more, I found that exposing the timeStart is crucial to knowing the appropriate instance to cancel a jump.

https://jsfiddle.net/p5LL5fc4/

@cvlab
Copy link

cvlab commented Mar 25, 2017

@bretkikehara Thanks, very useful patch! Minor changes:
Instead of

  return {
    jump,
    cancel,
    isJumping,
  };

I'd like to see

	jump.cancel = cancel;
	jump.isJumping = isJumping;

	// expose only the jump method
	return jump
jump('.target')
jump.cancel()

this will not break existing API, or much better:

function jump(target, options = {}) {
	...
	return {cancel, isJumping}
}
let myJump1 = jump('.target1', {container: '#container1'})
let myJump2 = jump('.target2', {container: '#container2'})
...
myJump1.cancel()

because with custom container support, I think, will be possible to run a few jumps simultaneously.

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

Successfully merging this pull request may close these issues.

3 participants