How can I hide an element when the page is scrolled?

后端 未结 1 1575
Happy的楠姐
Happy的楠姐 2020-12-03 00:55

Ok, I\'m a little stumped.

I\'m trying to think the angular way coming from a jQuery background.

The problem: I\'d just like to hide a fixed element if the w

相关标签:
1条回答
  • 2020-12-03 01:25

    A basic directive would look like this. One key point is you'll need to call scope.$apply() since scroll will run outside of the normal digest cycle.

    app = angular.module('myApp', []);
    app.directive("scroll", function ($window) {
        return function(scope, element, attrs) {
            angular.element($window).bind("scroll", function() {
                scope.visible = false;
                scope.$apply();
            });
        };
    });
    

    I found this jsfiddle which demonstrates it nicely http://jsfiddle.net/88TzF/

    0 讨论(0)
提交回复
热议问题