如何检测列表是否滚动?

发布于 2024-11-15 15:44:17 字数 52 浏览 2 评论 0原文

有没有办法检测列表是否滚动,例如list.isScrolling

Is there any way to detect whether a list is scrolling or not,likelist.isScrolling

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

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

发布评论

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

评论(4

永言不败 2024-11-22 15:44:17

因此,@Khaled 展示了一种使用 MX 组件来实现此目的的方法。如果您使用 Spark 组件,则该事件不起作用。相反,您可以监听 myList.scroller.viewport.verticalScrollPositionhorizo​​ntalScrollPosition 上的更改。

<fx:Declarations>
    <fx:int id="scrollingCount" />
</fx:Declarations>

<s:initialize>
    BindingUtils.bindSetter(function(x:*):void { scrollingCount++; }, myList.scroller.viewport, "verticalScrollPosition");
</s:initialize>

<s:VGroup>
    <s:Label text="Scrolling: {scrollingCount}" />
    <s:List id="myList" height="200" dataProvider="{myData}" />
</s:VGroup>

在这两种情况下,您都不会知道列表何时停止滚动(我不确定您是否想要)。您可能必须设置一个计时器,并且每当计时器关闭而没有任何滚动事件时,您就不再滚动了吗?

不幸的是,您没有解释您要实现的目标,我们无法充分回答您的问题。

So, @Khaled showed a way to do it with the MX component. If you are using the Spark component, that event doesn't work. Instead, you can listen to changes on myList.scroller.viewport.verticalScrollPosition or horizontalScrollPosition.

<fx:Declarations>
    <fx:int id="scrollingCount" />
</fx:Declarations>

<s:initialize>
    BindingUtils.bindSetter(function(x:*):void { scrollingCount++; }, myList.scroller.viewport, "verticalScrollPosition");
</s:initialize>

<s:VGroup>
    <s:Label text="Scrolling: {scrollingCount}" />
    <s:List id="myList" height="200" dataProvider="{myData}" />
</s:VGroup>

In neither of these cases do you get to know when the list stops getting scrolled (I'm not sure if you want it or not). You might have to set a timer and any time the timer goes off without any scrolling events, you are no longer scrolling?

Unfortunately, you haven't explained what you are trying to accomplish, wo we can't adequately answer your question.

北陌 2024-11-22 15:44:17

或者您可以在列表 itemrenderer 中执行类似这样的操作:

import spark.components.List;

[Bindable]
private var calcWidth:Number=195;   
private var listVerticalScroll:Boolean;
private var listHorizontalScroll:Boolean;

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
    var ownerVerticalScroll:Boolean=List(owner).scroller.verticalScrollBar.visible;
    var ownerHorizontalScroll:Boolean=List(owner).scroller.horizontalScrollBar.visible;
    if(ownerVerticalScroll!=listVerticalScroll){
        listVerticalScroll=ownerVerticalScroll;
        scrollBarChange()
    }

    super.updateDisplayList(unscaledWidth,unscaledHeight);
}

private function scrollBarChange():void {       
    if(listVerticalScroll){
        var newWidth:Number=195-(listVerticalScroll?15:0);
        calcWidth=newWidth;
    }
}

Or you can do somme thing like this in a list itemrenderer :

import spark.components.List;

[Bindable]
private var calcWidth:Number=195;   
private var listVerticalScroll:Boolean;
private var listHorizontalScroll:Boolean;

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
    var ownerVerticalScroll:Boolean=List(owner).scroller.verticalScrollBar.visible;
    var ownerHorizontalScroll:Boolean=List(owner).scroller.horizontalScrollBar.visible;
    if(ownerVerticalScroll!=listVerticalScroll){
        listVerticalScroll=ownerVerticalScroll;
        scrollBarChange()
    }

    super.updateDisplayList(unscaledWidth,unscaledHeight);
}

private function scrollBarChange():void {       
    if(listVerticalScroll){
        var newWidth:Number=195-(listVerticalScroll?15:0);
        calcWidth=newWidth;
    }
}
变身佩奇 2024-11-22 15:44:17

您可以使用 ScrollEvent.SCROLL :

import mx.events.ScrollEvent

myList.addEventListener(ScrollEvent.SCROLL, scrollHandler);

function scrollHandler(e:ScrollEvent):void
{
//myList is scrolling
}

you can use the ScrollEvent.SCROLL :

import mx.events.ScrollEvent

myList.addEventListener(ScrollEvent.SCROLL, scrollHandler);

function scrollHandler(e:ScrollEvent):void
{
//myList is scrolling
}
離殇 2024-11-22 15:44:17

或者你可以对 Spark 组件这样做!

http://blog.flexexamples.com/2009/05/31/detecting-when-the-vertical-scroll-bar-is-scrolled-on-a-spark-list-control-in-flex-4/ -- >

    <fx:Script>
        <![CDATA[
            import spark.components.VScrollBar;

            private function init():void {
                list.scroller.verticalScrollBar.addEventListener(Event.CHANGE, list_verticalScrollBar_change);
            }

            private function list_verticalScrollBar_change(evt:Event):void {
                var vsb:VScrollBar = evt.currentTarget as VScrollBar;
                var obj:Object = {};
                obj.type = evt.type;
                obj.val = vsb.value;
                obj.max = vsb.maximum;
                arrColl.addItem(obj);
                callLater(dgScroll);
            }

            private function dgScroll():void {
                dataGrid.verticalScrollPosition = dataGrid.maxVerticalScrollPosition;
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <mx:ArrayCollection id="arrColl" />
    </fx:Declarations>

    <s:HGroup horizontalCenter="0" verticalCenter="0">
        <s:List id="list"
                creationComplete="init();">
            <s:layout>
                <s:VerticalLayout gap="0"
                        horizontalAlign="contentJustify"
                        requestedRowCount="4" />
            </s:layout>
            <s:dataProvider>
                <s:ArrayList>
                    <fx:String>The</fx:String>
                    <fx:String>Quick</fx:String>
                    <fx:String>Brown</fx:String>
                    <fx:String>Fox</fx:String>
                    <fx:String>Jumps</fx:String>
                    <fx:String>Over</fx:String>
                    <fx:String>The</fx:String>
                    <fx:String>Lazy</fx:String>
                    <fx:String>Dog</fx:String>
                </s:ArrayList>
            </s:dataProvider>
        </s:List>
        <mx:DataGrid id="dataGrid"
                dataProvider="{arrColl}"
                width="200"
                verticalScrollPolicy="on">
            <mx:columns>
                <mx:DataGridColumn dataField="type" />
                <mx:DataGridColumn dataField="val" />
                <mx:DataGridColumn dataField="max" />
            </mx:columns>
        </mx:DataGrid>
    </s:HGroup>

</s:Application>

Or you can do it like this for spark component!

http://blog.flexexamples.com/2009/05/31/detecting-when-the-vertical-scroll-bar-is-scrolled-on-a-spark-list-control-in-flex-4/ -->

    <fx:Script>
        <![CDATA[
            import spark.components.VScrollBar;

            private function init():void {
                list.scroller.verticalScrollBar.addEventListener(Event.CHANGE, list_verticalScrollBar_change);
            }

            private function list_verticalScrollBar_change(evt:Event):void {
                var vsb:VScrollBar = evt.currentTarget as VScrollBar;
                var obj:Object = {};
                obj.type = evt.type;
                obj.val = vsb.value;
                obj.max = vsb.maximum;
                arrColl.addItem(obj);
                callLater(dgScroll);
            }

            private function dgScroll():void {
                dataGrid.verticalScrollPosition = dataGrid.maxVerticalScrollPosition;
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <mx:ArrayCollection id="arrColl" />
    </fx:Declarations>

    <s:HGroup horizontalCenter="0" verticalCenter="0">
        <s:List id="list"
                creationComplete="init();">
            <s:layout>
                <s:VerticalLayout gap="0"
                        horizontalAlign="contentJustify"
                        requestedRowCount="4" />
            </s:layout>
            <s:dataProvider>
                <s:ArrayList>
                    <fx:String>The</fx:String>
                    <fx:String>Quick</fx:String>
                    <fx:String>Brown</fx:String>
                    <fx:String>Fox</fx:String>
                    <fx:String>Jumps</fx:String>
                    <fx:String>Over</fx:String>
                    <fx:String>The</fx:String>
                    <fx:String>Lazy</fx:String>
                    <fx:String>Dog</fx:String>
                </s:ArrayList>
            </s:dataProvider>
        </s:List>
        <mx:DataGrid id="dataGrid"
                dataProvider="{arrColl}"
                width="200"
                verticalScrollPolicy="on">
            <mx:columns>
                <mx:DataGridColumn dataField="type" />
                <mx:DataGridColumn dataField="val" />
                <mx:DataGridColumn dataField="max" />
            </mx:columns>
        </mx:DataGrid>
    </s:HGroup>

</s:Application>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文