2017-03-21 13 views
0

私はAngularJSを初めて使い、ウィンドウスクロールでbodyタグのCSSスタイルの値を変更する指示をしました。これは指令です:AngularJSディレクティブからボディCSSスタイルのプロパティを変更する

app.directive("parallaxDir", function ($window, $document) { 
    return function (scope, element, attrs) { 
     angular.element($window).bind("scroll", function() { 
      console.log('Scroll in da directive'); 
      ** Here I want to modify the body tag css style to: ** 
      ** background-position-y = $window.pageYOffset/2) + "px") ** 
     }); 
    }; 
}); 

どうすればよいですか?

ありがとうございます。

答えて

0

私は解決策でつまずい:最終的なコードは次のようになります http://corpus.hubwiz.com/2/angularjs/16725136.html

app.directive("parallaxDir", function ($window, $document) { 
    return function (scope, element, attrs) { 
     angular.element($window).bind("scroll", function() { 
      var body = angular.element(document).find('body'); 
      body.css("background-position-y", ($window.pageYOffset/2) + "px"); 
      scope.$apply(); 
     }); 
    }; 
}); 
関連する問題