2016-09-29 3 views
0

ユーザーがwindows height.soを変更するたびに要素の位置をカウントする必要があります。ディレクティブを作成します。 ?ユーザーがウィンドウの高さを変更したときに、角度でイベントをトリガーする方法は?

'use strict'; 
    angular.module "myApp" 
    .directive 'uibPosition',['$position','$document','$timeout', ($position,$document,$timeout)-> 
    return { 
     restrict: 'EAC', 
     link: (scope, element, attr) -> 
//I want to Trigger this event when user change windows height 
     $timeout -> 
      if $document.height() - $position.position(element).top < 500 
      element[0].querySelector('.custom-popup-wrapper').style.top = 'auto' 
      element[0].querySelector('.custom-popup-wrapper').style.bottom = 40 + 'px' 
      else 
      element[0].querySelector('.custom-popup-wrapper').style.top = $position.position(element).top+40+'px' 
    } 
    ] 

はそれを行う方法を私は本当にそれが

答えて

1

あなたはディレクティブにウォッチャを追加することができ感謝:

 var w = angular.element($window); 

     scope.getWindowDimensions = function() { 
      return { 
       "h": w.height(), 
       "w": w.width() 
      }; 
     }; 
     var watcherTimeout; 
     scope.$watch(scope.getWindowDimensions, function (newValue) { 
      $timeout.cancel(watcherTimeout); 
      watcherTimeout = $timeout(function(){ 
       scope.callback(); // call callback function 
      }, 300); 
     }, true); 

     w.bind("resize", function() { 
      scope.$apply(); 
     }); 
+0

'WindowSizeService'何ですか? –

+0

不要な部分でした。申し訳ありません:) – olysachok

+0

それはworks.thanksようです –

関連する問題