Jump to content
Search Community

tweenlite & mousewheel [SOLVED]

tean test
Moderator Tag

Recommended Posts

if i have a movieclip on the stage and i do this:

 

stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);
function handleMouseWheel(e:MouseEvent):void {

var _delta:int = e.delta > 0 ? 1 : -1;

mc.y += _delta * 20;

}

 

and if i roll my mouse wheel once movieclip will move by 20, and if i roll mouse wheel multiple times in one go, for example 4 times, movieclip will move by 80.

 

is there a way to do this with tweenlite?

i tried it like this by the effect is not the same:

TweenLite.to(mc, .5, {y:String(_delta * 20)});

(while i am rolling the mouse wheel movieclip moves constantly, but as soon as i let it go, it just finished one more tween).

i would like if i roll 4 times for example that it tweens that distance?

is that possible?

Link to comment
Share on other sites

Sure, just track the end value as a variable and plug that into the tween. The problem you were running into was just a logic thing - your code was always using relative values, so if a tween was halfway done when the user rolled their mouse again, it would add another 20 to the current position which was only halfway to its destination at that point.

 

var destY:Number = mc.y;
stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);
function handleMouseWheel(e:MouseEvent):void {
  var _delta:int = e.delta > 0 ? 1 : -1;
  destY += _delta * 20;
  TweenLite.to(mc, .5, {y:destY});
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...