LoginSignup
0
1

More than 5 years have passed since last update.

ionicでanchorScrollを使う

Last updated at Posted at 2016-02-02

ionicでアンカーを使ってion-contentをscrollさせる際にはまったのでメモ。

1.$ionicScrollDelegateを使う

ionicではAngularJSの\$anchorScrollが使えないため、代わりに\$ionicScrollDelegateを使う。

hoge-ctrl.js
$scope.scrollToAnchor = function(anchor) {
  $location.hash(anchor);
  $ionicScrollDelegate.anchorScroll(true);
};

2.$anchorScrollの自動スクロールをオフにする

デフォルトでは、\$location.hash()でアンカーを操作した際に自動で\$anchorScrollが動いてしまうので、自動スクロールをオフにする。

app.js
var application = angular.module('starter', ['ionic', 'starter.controllers']);
application.config(['$anchorScrollProvider', function($anchorScrollProvider) {
    $anchorScrollProvider.disableAutoScrolling();  // 自動スクロールをオフ
}]);

参考
https://forum.ionicframework.com/t/hashbang-scroll-cant-scroll-up-to-top-of-content-manually/633
http://knightso.hateblo.jp/entry/2014/10/23/093413

0
1
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
0
1