Nick Ginanto
Nick Ginanto

Reputation: 32130

Undeclared Javascript Function

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

Answers (2)

sasi
sasi

Reputation: 4318

if (isScrolledIntoView(".my_class")){

Upvotes: 2

Dipesh Parmar
Dipesh Parmar

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

Related Questions