Help us understand the problem. What is going on with this article?

[Sencha Touch]現在のスクロール位置を取得する

More than 5 years have passed since last update.

スクロール可能なコンテナは、getScrollable().getScroller()でExt.scroll.Scrollerのインスタンスが取得できる。
APIドキュメントには記載がないが、Scrollerのpositionプロパティから現在のスクロール位置を取得できるっぽい。

Scrollerには他にもいくつかのプロパティが格納されている。

  • position
    現在のスクロール位置(表示されいてる範囲の左上座標)
  • maxPosition
    一番右下までスクロールした時の左上座標
  • givenContainerSize
    コンテナのサイズ
  • givenSize
    スクロールされる領域のサイズ
Ext.define('MyApp.view.Main', {
    extend: 'Ext.Container',
    xtype: 'main',
    config: {
        items: [{
            centered: true,
            width: 100,
            height: 150,
            xtype: 'list',
            itemTpl: '{name}'
        }],
    },
    initialize: function() {
        this.callParent();

        var list = this.down('.list'),
            data = [];
        for (i = 0; i < 30; i++) {
            data.push({name: 'item' + i});
        }
        list.setData(data);

        var scroller = list.getScrollable().getScroller();
        scroller.on({
            scroll: function(scroller) {
                console.log("コンテナサイズ", scroller.givenContainerSize.y);
                console.log("スクロール領域サイズ", scroller.givenSize.y);
                console.log("最大スクロール範囲", scroller.maxPosition.y);
                console.log("スクロール位置", scroller.position.y);
            }
         });
    },
});
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away