繁体   English   中英

自动滚动到底部

[英]Auto scroll to Bottom

我正在使用聊天屏幕进行应用程序。 但正如普通屏幕一样,它开始从上到下滚动。 但它应该是从底部到顶部。 该应用程序位于Telerik Nativescript平台中。

view.xml用

<ScrollView row="0" col="0">  
    <StackLayout class="history-content-area">
        <Repeater items="{{messageHistory}}">
            <Repeater.itemTemplate>
                <StackLayout>
                    <!-- ITEMS GO HERE -->
                </StackLayout>
            </Repeater.itemTemplate>
        </Repeater>
    </StackLayout>
</ScrollView>

我在上面的代码中需要帮助如何在页面加载时自动滚动到底部? 如果您需要javascript代码,请告诉我们。

提前致谢。

在ScrollView上,您可以使用scrollToVerticalOffset ,您可以在其中传递要滚动到的偏移量。

例如: view.xml

<ScrollView row="0" col="0" id="myScroller">  
    <StackLayout class="history-content-area">
        <Repeater items="{{messageHistory}}">
            <Repeater.itemTemplate>
                <StackLayout>
                    <!-- ITEMS GO HERE -->
                </StackLayout>
            </Repeater.itemTemplate>
        </Repeater>
    </StackLayout>
</ScrollView>

view.js

mScroller = page.getViewById("myScroller");

var offset = mScroller.scrollableHeight; // get the current scroll height
mScroller.scrollToVerticalOffset(offset, false); // scroll to the bottom

假设你的ScrollView的id为'id-scroller'。 然后在你的View.js中你做:

let scroller = page.getViewById('id-scroller');

setTimeout(function() {
  scroller.scrollToVerticalOffset(scroller.scrollableHeight, true);
}, 1);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM