0

I have a pictures website and I want to be able to add impressions to the database when a visitor scroll down the images. Each image viewed equal to 1 impression. This feature can be found in Facebook post impressions.

This is what I have come up with so far:

$(window).scroll(function(){
        index = $(".Picture-1A:eq(3)").offset().top;
        elementHeight = $(".Picture-1A").height();
        if(($(document).scrollTop() >= index) && ($(document).scrollTop() <= index + elementHeight)){
            // Do something here
        }
    });

Of course I will be using jQuery and Ajax.
The example above is my first attempt. I don't know how I can do it for each image. I know how to do it for one image using the :eq(index)
But I want it to update the database for each image viewed.

1
Contributor
1
Reply
8
Views
1 Year
Discussion Span
Last Post by FarrisFahad
1

I have found great plugin that works perfectly it's called, waypoint. You can search for it using Google
Here is a link to the plugin: http://imakewebthings.com/waypoints/
Just follow the guide on the website, easy and simple.
If you are having problems search through Stackoverflow using keyword: jquery waypoint

Votes + Comments
thanks for sharing!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.