Reputation: 954
I have problem with my js codes,I want to compare vertical distance from top of an element with scroll distance and if scroll distance is more than distance from the top of an element fixed the position of div with "thead" id in top of the page.
my js code :
var distance = $("#thead").offset().top;
var wdistance = $(window).scrollTop();
if (wdistance > distance) {
alert('this is test');
};
demo in
Upvotes: 1
Views: 421
Reputation: 113475
You just need to add a scroll handler:
var distance = $("#thead").offset().top;
$(window).scroll(function () {
var wdistance = $(window).scrollTop();
if (wdistance > distance) {
alert('this is test');
};
});
Upvotes: 1