LoginSignup
1
0

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-01-28

スクロール可能なコンテナは、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);
            }
         });
    },
});
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0