gpt4 book ai didi

actionscript-3 - AS3 滚动条内容公式

转载 作者:行者123 更新时间:2023-12-04 07:02:06 25 4
gpt4 key购买 nike

我已经创建了一个水平滚动条,现在我被困在如何在滚动条处于某个位置时计算内容的位置。

private function checkDrag(event:Event):void {
var procent:Number = (stage.stageWidth/(buttonLR.x+buttonLR.width))*(LISTmc.width)
if (drag) {
TweenLite.to(LISTmc,1,{x:-procent});
}

//buttonLR width is also stretched according to how many data loads in,
thats why I'm trying to target the center of buttonLR
}

每次单击按钮时,都会从左到右添加一个新内容,因此滚动条将移动到栏的右端,因为它从左到右滚动,并显示最新的内容。所以如果我想回到之前的内容,我必须向左拖动滚动条。

目前我的代码在加载新内容并单击滚动条后,内容将移动到舞台左侧的末尾(内容 x=0 的右上角),拖动它会使内容向左移动更多的。

最佳答案

要正确执行此操作,您需要找到屏幕外的宽度 (extraWidth),然后相应地计算位置。当您计算放置按钮的百分比时,我还会从 stageWidth 中减去按钮的宽度:

   private function checkDrag(event:Event):void {
if (LISTmc.width < stage.stageWidth) {
return;
}
var extraWidth:Number = LISTmc.width - stage.stageWidth;
var percentage:Number = buttonLR.x / (stage.stageWidth - buttonLR.width )
var newXPos:Number = - extraWidth * percentage;
if (drag) {
TweenLite.to(LISTmc,1,{x:newXPos});
}
}

希望对你有帮助

关于actionscript-3 - AS3 滚动条内容公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1686803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com