我有一张名为tileListCanvas
的画布,当鼠标在tileListCanvas
上上下移动时,我会垂直滚动。一切都工作正常,但我想添加一个补间效果滚动行为,以便滚动逐渐减慢,并在用户停止移动鼠标时停止。滚动行为由
target = tileListCanvas.verticalScrollPosition -= (10 - yDiff)
用于向上滚动和
target = tileListCanvas.verticalScrollPosition += (10 + yDiff)
向下滚动。
如果有人能让我知道如何做到这一点,那将是我的一天!
[Bindable]private var previousX:Number = 0;
[Bindable]private var previousY:Number = 0;
[Bindable]private var currentX:Number = 0;
[Bindable]private var currentY:Number = 0;
[Bindable]private var xDir:String;
[Bindable]private var yDir:String;
[Bindable]private var xDiff:Number = 0;
[Bindable]private var yDiff:Number = 0;
[Bindable]private var lastX:Number = 0;
[Bindable]private var lastY:Number = 0;
[Bindable]private var speed:Number;
[Bindable]private var target:Number = 0;
private function initMouseDirectionChecker():void
{
tileList.addEventListener(MouseEvent.MOUSE_MOVE, checkDirection);
}
private function beginScrolling(mouseEvent:MouseEvent):void
{
tileListCanvas.verticalScrollPosition -= 5;
}
public function checkDirection(e:MouseEvent):void
{
getHorizontalDirection();
getVerticalDirection();
dir1.text = "x: " + xDir
dir2.text = "y: " + yDir;
}
//Horizontal
private function getHorizontalDirection():void
{
previousX = currentX; //Checks the last position
currentX = stage.mouseX; //Gets the current position
if (previousX > currentX) //Compares both positions to determine the direction
{
xDir = "left";
}
else if (previousX < currentX)
{
xDir = "right";
}
else
{
xDir = "none";
}
}
//Vertical
private function getVerticalDirection():void
{
previousY = currentY; //Checks the last position
currentY = stage.mouseY; //Gets the current position
if (previousY > currentY) //Compares both positions to determine the direction
{
yDir = "up";
target = tileListCanvas.verticalScrollPosition -= (10 - yDiff);
}
else if (previousY < currentY)
{
yDir = "down";
target = tileListCanvas.verticalScrollPosition += (10 + yDiff);
}
else
{
yDir = "none";
}
}
答案 0 :(得分:0)
非常感谢快速回复!
我按照你的建议从greensock.com下载了GASP,在那里我可以将greensock swc导入我的项目并访问TweenLite。我使用下面的代码来实现我想要的滚动效果。
TweenLite.to(tileListCanvas, 2, {verticalScrollPosition:currentY +10, ease:Back.easeOut});
希望这可以帮助其他人。