[英]Tweening effect for scrolling list in AS3 Flex
我有一個名為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";
}
}
感謝迅速的答復,不勝感激!
我按照您的建議從greensock.com下載了GASP,在那里我可以將greensock swc導入到我的項目中並訪問TweenLite。 我使用下面的代碼來實現所需的滾動效果。
TweenLite.to(tileListCanvas, 2, {verticalScrollPosition:currentY +10, ease:Back.easeOut});
希望這可以幫助其他人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.