Hey there, I'm a newcomer to AngularJS with a background in jQuery. I'm trying to create a fixed-top navbar using AngularJS that has a background which changes from transparent to opaque as the window is scrolled. Unfortunately, I'm struggling to connect the window scroll event to the $scope variable.
This is what I've come up with so far, but it's not working properly:
function bgScroll($scope) {
angular.element(window).bind('scroll', function () {
$scope.scroll = window.pageYOffset;
$scope.height = document.getElementById('main-header').offsetHeight;
$scope.a = $scope.scroll / $scope.height;
$scope.bgColor = 'rgba(0,0,0,' + $scope.a + ')';
});
}
Here's how it looks on the view side:
<div ng-controller="bgScroll">
<nav class="navbar navbar-inverse navbar-bw navbar-fixed-top" role="navigation" style="background-color: {{ bgColor }};">
...
</nav>
</div>
I would really appreciate any assistance or suggestions you can provide! Thanks in advance.