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:

        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.

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

commented: thanks for sharing! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.