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.