Within the link function part of a directive we have access to the element
object. I wish to determine if the element
object is within the current viewport / if it is available.
I currently have the following:
link: function (scope, element, attrs, controller) {
var page = angular.element(window);
page.bind('scroll', function () {
var windowScroll = page[0].pageYOffset,
windowHeight = page[0].innerHeight;
// elementScroll = element.xpos; - this is undefined?
// elementScroll = element.getBoundingClientRect().top - this does not work... undefined?
// elementScroll = element[0].getBoundingClientRect().top - this does not work... undefined?
// ... logic follows that if elementScroll is between windowScroll & windowScroll + windowHeight it is visible!
});
I just can't seem to get the x and y positions for my specific element (the directive may be repeated many times).
Please note that I do not intend to install or use jQuery in my application.