Reputation: 32130
I am sure something is wrong with my function declaration
$(window).ready(function(){
if isScrolledIntoView(".my_class"){
$("#some_id").hide();
}
});
function isScrolledIntoView(elem)
{
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
Why doesn't this work?
Upvotes: 0
Views: 581
Reputation: 27364
You forget to wrap ()
around if condition also use window.load
or document.ready
.
$(window).load(function(){
if (isScrolledIntoView(".my_class")){
$("#some_id").hide();
}
});
Upvotes: 3