I m trying to get offset().top of an element <div class='profile'></div> present in a ngView controlled by app.js but the console displays an error:
Uncaught TypeError: Cannot read property 'top' of undefined
jQuery code :
var topOfOthDiv = $('.profile').offset().top;
index.ejs
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="main/js/main.js"></script>
...
</head>
<body>
<div class="ui inverted top fixed nbar hidden menu">...</div>
<div class="ui main container " ng-view>
</div>
</body>
main.js
$(document)
.ready(function() {
var topOfOthDiv = $('.profile').offset().top;
$(window).scroll(function() {
if($(window).scrollTop() > topOfOthDiv) { //scrolled past the other div?
$('.fixed.menu').transition('fade in'); //reached the desired point -- show div
}
if($(window).scrollTop() < topOfOthDiv) { //scrolled past the other div?
$('.fixed.menu').transition('fade out'); //reached the desired point -- show div
}
});
})
;
In ng-view i load my different view which has .profile clss div
The code works fine if .profile class is in index.ejs