$ ionicScrollDelegate锁定滚动值

时间:2015-10-22 13:10:06

标签: angularjs cordova ionic

当我在我的cordova应用程序中获取结果列表时,我想使用此功能将其滚动到指定的元素:

    $scope.roll = function () {
        //var rankScroll = $ionicScrollDelegate.$getByHandle('rank');

        var meElement = document.getElementById('scroll');
        if (!meElement) {
            $ionicScrollDelegate.scrollTo(0, 0);
            return;
        }

        var top = meElement.getBoundingClientRect().top - 50;
        $ionicScrollDelegate.scrollTo(0, top);
        console.log(top);
        console.log($ionicScrollDelegate.getScrollView());

    }

它工作得很好,但我无法滚动到列表中的任何其他位置。我想解锁此解决方案中的滚动或找到更好的解决方案。它应该在加载的页面上滚动,而不是单击。

一切顺利

1 个答案:

答案 0 :(得分:0)

由于$ scope的绑定,该函数会锁定您的滚动。

如果您只想在加载视图时调用该函数,则应在加载视图时调用它一次。

您可以通过这种方式在您的控制器中执行此操作:

var roll = function () {
    //var rankScroll = $ionicScrollDelegate.$getByHandle('rank');

    var meElement = document.getElementById('scroll');
    if (!meElement) {
        $ionicScrollDelegate.scrollTo(0, 0);
        return;
    }

    var top = meElement.getBoundingClientRect().top - 50;
    $ionicScrollDelegate.scrollTo(0, top);
    console.log(top);
    console.log($ionicScrollDelegate.getScrollView());

}
$scope.$on("$ionicView.loaded", function (scopes, states) {
    roll();
});

您可以在此ion-view Document

中查看更多$ ionicView事件