如何将控制器添加到离子提供程序

时间:2018-07-12 05:29:43

标签: angularjs ionic-framework

请帮助我在ionic提供商中添加以下脚本,我是ionic的初学者

angular.module('ionicApp', ['ionic'])

.controller('MyCtrl', function($scope, $ionicScrollDelegate, $window) {

  $scope.changeHeader = function (id) {
     var el = document.getElementById(id),
         windowHeight = $window.innerHeight,
         scrollPosition = $ionicScrollDelegate.getScrollPosition().top - windowHeight/5;
     var alpha = scrollPosition / windowHeight * 3;

     el.style.backgroundColor = "rgba(252,193,0," + alpha +")";
  } 

  angular.element(document).ready(function () {
        document.getElementById('myFunction').onscroll = function () {

      console.log('scrolling!');
      $scope.changeHeader('ben-header');

    };
  });

});

0 个答案:

没有答案