使用鼠标滚轮的 Flex 列表滚动速度

发布于 2024-10-19 15:45:15 字数 776 浏览 5 评论 0原文

我有一个扩展 List 的自定义类,我将其用作容器。然而,鼠标滚轮的滚动速度太快,因为即使您只移动滚轮一点点,它也会滚动负载。我尝试将事件侦听器添加到 MouseEvent.MOUSE_WHEEL 的列表中并设置 event.delta 的值,但这没有效果。有谁知道我怎样才能让它慢一点?

我的自定义类没什么特别的,我只是创建了它,这样我就可以为不同的项目类型提供不同的 itemRenders。它看起来像:

public class MultipleRenderersList extends List
{
    override public function createItemRenderer(data:Object):IListItemRenderer
    {
        if (data is IRenderable)
        {
             return data.getDiaryRenderer();
        }
        else if (data is Array) 
        {
             if (data.length > 0)
             {
                  if (data[0] is IRenderable)
                  {
                       return data[0].getDiaryRenderer(data);
                  }
             }
        }
        return null;
    }
} 

I have a custom class that extends List which I am using as a container. However, the scroll speed is too fast on the mouse wheel, as in it scrolls loads even if you only move the wheel a tiny bit. I tried adding an event listener to my list for MouseEvent.MOUSE_WHEEL and setting the value of event.delta but this has had no effect. Does anyone know how I can make it slower?

My custom class is nothing special, I just created it so I could have a different itemRenders for different item types. It looks like:

public class MultipleRenderersList extends List
{
    override public function createItemRenderer(data:Object):IListItemRenderer
    {
        if (data is IRenderable)
        {
             return data.getDiaryRenderer();
        }
        else if (data is Array) 
        {
             if (data.length > 0)
             {
                  if (data[0] is IRenderable)
                  {
                       return data[0].getDiaryRenderer(data);
                  }
             }
        }
        return null;
    }
} 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

安稳善良 2024-10-26 15:45:15

List 类有一个可以重写的 mouseWheelHandler 函数。只需重写该函数,更新 mouseevent 的 delta 属性,然后调用 super.此示例将增量四分之一,从而大幅降低速度:

package
{
  import flash.events.Event;
  import flash.events.MouseEvent;

  import mx.controls.Alert;
  import mx.controls.List;

  public class MyList extends List
  {

    override protected function mouseWheelHandler(event:MouseEvent):void {
      event.delta = event.delta/4;
      super.mouseWheelHandler(event);
    }

  }
}

但是,在许多情况下,滚动速度/增量将脱离系统首选项,因此这样做可能会导致某些用户出现意外行为。添加处理程序和更新增量失败的原因是此时 mouseWheelHandler 已经被调用。

The List class has a mouseWheelHandler function that you can override. Just override the function, update the delta property of the mouseevent, and call super. This example will quarter the delta, reducing the speed substantially:

package
{
  import flash.events.Event;
  import flash.events.MouseEvent;

  import mx.controls.Alert;
  import mx.controls.List;

  public class MyList extends List
  {

    override protected function mouseWheelHandler(event:MouseEvent):void {
      event.delta = event.delta/4;
      super.mouseWheelHandler(event);
    }

  }
}

However, in many cases the scroll speed / delta will be driven off of a system preference, so doing this may cause unexpected behavior for some users. The reason that adding the handler and updating the delta failed to work is that by that point mouseWheelHandler had already been called.

冬天的雪花 2024-10-26 15:45:15

修改此值的一个非常简单的方法是更改​​ VerticalLineScrollSize 属性。这是所有容器的属性,默认为 5。(对于 flex 3)

A very simple way to modify this is to change the verticalLineScrollSize property. This is a property of all containers and it defaults to 5. (for flex 3)

硪扪都還晓 2024-10-26 15:45:15

实际上,HandOfCode所说的与这里无关。因为他犯了和我一样的错误,就是认为List组件或者TileList组件是容器。他们不是。因此,它们没有 VerticalLineScrollSize 属性。

Sean 解决方案是唯一适合我的案例的解决方案。我想补充一点,event.delta 可能具有正值或负值,具体取决于轮子动作的方向。因此,如果您打算滚动,您最好这样做,例如一次一行:

    override protected function mouseWheelHandler(event:MouseEvent):void
    {
        event.delta = (event.delta > 0) ? 1:-1;
        super.mouseWheelHandler(event);
    }

Actually, what HandOfCode said isn't relevant here. Because he made the same mistake as i did, which is to think that a List component or TileList component are containers. They aren't. So, they don't have verticalLineScrollSize property.

Sean solution is the only one that worked for my case. I would add that event.delta may have a positive or negative value depending of the direction of the wheel action. So you better do something like this if you plan to scroll, for example one line at a time :

    override protected function mouseWheelHandler(event:MouseEvent):void
    {
        event.delta = (event.delta > 0) ? 1:-1;
        super.mouseWheelHandler(event);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文