我也想触发" master" $(window).resize(function(){})的指令;

时间:2015-08-05 08:24:56

标签: javascript jquery angularjs cordova

我想触发"掌握"指令$(window).resize(function(){});我的代码在下面给出

 App.directive('master',function () {
        function link(scope, element, attrs) { //scope we are in, element we are bound to, attrs of that element
          scope.$watch(function(){ //watch any changes to our element
            scope.slide_style = { //scope variable style, shared with our controller
               // height:element[0].offsetHeight+'px', //set the height in style to our elements height
                width:element[0].offsetWidth+'px' //same with width
              };
             scope.scroller_style = {
                 width: (element[0].offsetWidth * scope.boards.length )+'px'
             } 
             if (typeof myScroll !== 'undefined') {
               myScroll.refresh(); 

             }
          });


        }
          return {
            restrict: 'AE', //describes how we can assign an element to our directive in this case like <div master></div
            link: link // the function to link to our element
          };
    }); 

1 个答案:

答案 0 :(得分:0)

您可以为$ window变量实现一个观察器并调用您的更新函数。通过观察您创建调整大小事件的尺寸。

指令

App.directive('master',function ($window) {
function link(scope, element, attrs) { 
    var window = angular.element($window); 
    scope.windowDimension = function(){
        return {"height": window.height(), "width" : window.width()};
    };  //Create a function that will return the windows dimensions
    scope.$watch("windowDimension",function(newData, oldData){
        //Call any update function here
        var newHeight = newData.height;
        var newWidth = newData.width;
    });
}