【问题标题】:AS3 Scrollbar content formulaAS3 滚动条内容公式
【发布时间】:2009-11-06 10:43:38
【问题描述】:

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

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 的右角),拖动它会使内容向左移动更多。

【问题讨论】:

    标签: actionscript-3 scroll


    【解决方案1】:

    要正确执行此操作,您需要找到屏幕外的宽度(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});
          }
        }
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      这也是一个很棒的 OOP 滚动条,你可以使用它,它还支持模糊、缓动等... 还使用 Greensock 缓动效果

      AS3 Scrollbar (ease, blur, abstract, OOP)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-02
        • 1970-01-01
        • 2015-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多