Alon Shmiel
Alon Shmiel

Reputation: 7121

Is element displayed in div

I am trying to check if the element is displayed in the div(divContent) or not.

The starting point is: elements: 1,2,3,4 are displayed.

So why the function: checkIfInView, returns true for element number 6?

This is my jsfiddle:

http://jsfiddle.net/Ht6Ym/2971/

function checkIfInView(element){
    var offset = element.offset().top - $('#divContent').scrollTop();

    if(offset > $('#divContent').innerHeight){
        // Not in view
        return false;
    }
   return true;
}

thanks!

Upvotes: 1

Views: 60

Answers (1)

Joseph Marikle
Joseph Marikle

Reputation: 78520

You're not calling innerHeight. You need the parenthesis for it to execute the function. Otherwise you are evaluating against the function declaration (not sure if that's the right term for it. Correct me if I'm wrong please).

Change

if(offset > $('#divContent').innerHeight){

to

if(offset > $('#divContent').innerHeight()){

Upvotes: 4

Related Questions