mercredi 15 juin 2016

Postion().top is not consistant due angular DOM still loading


Position top is not consistant every time , If user scrolls down when dom is still loading position will be different.

 angular.module('users').directive('appplyProperty', ['$window', '$timeout',
        function ($window, $timeout) {
            var $win = angular.element($window);
            return {
                restrict: 'A',
                link: function (scope, element, attrs) {
                  var = offsetTop = element.offset().top;

                 $win.on('scroll', function (e) {
                    var checkTheTop = $window.scrollY - offsetTop;
                      if (checkTheTop > 0) {
                         // apply css property top = checkTheTop ;
                        } else {
                        //do something
                 }
                });
             });
          }
}]);

How to make sure position is calculated only after DOM is loaded or condition that now nothing is happening in the dom calculate position ?


Aucun commentaire:

Enregistrer un commentaire