Custom-Scroll three lists using one javascript - php

I have just come a little bit unstuck, I have a list which I populate with PHP, and a javascript file which creates the scrolling effect on the list so I can scroll up and down.
But I need three of these list boxes on the same page, and when I go to put another 2 of the lists in, they are not generated only the first is. I need to be able to have all three on the page. Any help with this would be fantastic!
Kind regards,
Alistair
<div id="mContainer">
<div id="upArrow"></div>
<div id="nContainer">
<ul id="listContainer">
<?php
connect();
$sql="SELECT drivers_id, firstname,image FROM drivers";
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result)){
echo "<li><a id='".$row['drivers_id']."' onclick='return showPic(this)' onfocus='this.hideFocus=true;' href='".$row['image']."'>".$row['firstname']."</a></li>";
}
?>
</ul>
</div>
<div id="downArrow">
</div>
</div>
**JAVASRIPT FILE BELOW**
window.onload=init;
var d=document;
var lContainer; // object reference for the UL
var currentTop=0; // the current Y position of the UL
var zInterval = null; // animation thread interval
var direction; // direction we're scrolling the UL. 0==up, 1==down
var startTop=0; // the starting top of the UL
var scrollRate=8; // initial rate of scrolling
var scrollTick=0; // keeps track of long we've scrolled so we can slow it down accordingly
var listHeight=60; // the current height of the UL
var MAX_SCROLL_TICK=4; // the maximum value of scrollTick before it's reset
var MIN_LIST_HEIGHT=145; // contracted height of the list
var REBOUND = 0; // the value of scrollRate when we stop scrolling
function init() {
if(!d.getElementById)return; // bail out if this is an older browser
up=d.getElementById("upArrow");
down=d.getElementById("downArrow");
// apply onclick behaviors to the up arrow, down arrow and expansion control elements
down.onmousedown=function(){
scrollObjects(0);
}
up.onmousedown=function(){
scrollObjects(1);
}
lContainer = d.getElementById("listContainer");
d.getElementById("nContainer").style.height=MIN_LIST_HEIGHT+"px";
}
function scrollObjects(dir) {
if(zInterval)return; // already scrolling.
if((!dir && currentTop<=-300) || (dir && currentTop==0))
return; // dont scroll up if we're at the top or down if at the bottom of the list
direction=dir;
zInterval=setInterval("animate()",20);
}
function animate() {
// increment or decrement currentTop based on direction
if(!direction) {
currentTop-=scrollRate;
} else {
currentTop+=scrollRate;
}
scrollTick++;
if(scrollTick>=MAX_SCROLL_TICK) {
scrollRate--; // slow the scroll rate down for a little style
scrollTick=0;
}
lContainer.style.top=currentTop+"px";
if(scrollRate<=REBOUND) {
// scroll is finished. clear the interval and reset vars for the next scroll
clearInterval(zInterval);
zInterval=null;
startTop=currentTop;
scrollTick=0;
scrollRate=8;
}
}

First, step up to jQuery. You'll eventually be immensely glad you did.
Next, don't use inline JavaScript! Ditto on the gladness part.
Here's the existing functionality in jQuery. The multi-list version is below the fold.
Add:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
(or load a version of the jQuery file to your own website.)
PHP:
<div id="mContainer">
<div id="upArrow"></div>
<div id="nContainer">
<ul id="listContainer">
<?php
connect();
$sql = "SELECT drivers_id, firstname, image FROM drivers";
$result = mysql_query($sql);
while ($row=mysql_fetch_array($result) ) {
echo "<li><a id='".$row['drivers_id']."' href='".$row['image']."'>".$row['firstname']."</a></li>";
}
?>
</ul>
</div>
<div id="downArrow"></div>
</div>
Additional CSS:
ul#listContainer li > a:focus {
outline: none;
}
JavaScript:
$(document).ready (init);
//--- Global variables!
var lContainer; // object reference for the UL
var currentTop = 0; // the current Y position of the UL
var zInterval = null; // animation thread interval
var direction; // direction we're scrolling the UL. 0==up, 1==down
var startTop = 0; // the starting top of the UL
var scrollRate = 8; // initial rate of scrolling
var scrollTick = 0; // keeps track of long we've scrolled so we can slow it down accordingly
var listHeight = 60; // the current height of the UL
var MAX_SCROLL_TICK = 4; // the maximum value of scrollTick before it's reset
var MIN_LIST_HEIGHT = 145; // contracted height of the list
var REBOUND = 0; // the value of scrollRate when we stop scrolling
function init() {
//-- Activate click and focus handlers on the li elements.
$("ul#listContainer li > a").click ( function () { showPic (this); } )
// This next is IE only! use CSS.
.focus ( function () { this.hideFocus=true; } );
//-- Apply onclick behaviors to the up/down arrow and expansion control elements.
$("#downArrow").mousedown ( function () { scrollObjects (0); } );
$("#upArrow") .mousedown ( function () { scrollObjects (1); } );
lContainer = $("#listContainer");
$("#nContainer").css ('height', MIN_LIST_HEIGHT + "px");
}
function scrollObjects(dir) {
if (zInterval) return; // already scrolling.
// dont scroll up if we're at the top or down if at the bottom of the list
if ((!dir && currentTop <= -300) || (dir && currentTop == 0)) return;
direction = dir;
zInterval = setInterval (animate, 20);
}
function animate() {
// increment or decrement currentTop based on direction
if (!direction) {
currentTop -= scrollRate;
} else {
currentTop += scrollRate;
}
scrollTick++;
if (scrollTick >= MAX_SCROLL_TICK) {
scrollRate--; // slow the scroll rate down for a little style
scrollTick = 0;
}
lContainer.css ('top', currentTop + "px");
if (scrollRate <= REBOUND) {
// scroll is finished. clear the interval and reset vars for the next scroll
clearInterval(zInterval);
zInterval = null;
startTop = currentTop;
scrollTick = 0;
scrollRate = 8;
}
}
See this in action at jsFiddle.
Multi-List Version:
And now, with the awesome might of jQuery, we will:
Enable multi-list operation.
Reduce the dependence on "magic number" dimensions.
Fix the apparent over-scroll problem.
Make click-and-hold work the way the user expects.
First, change all the container and arrow ids to classes, like so:
<div class="mContainer">
<div class="upArrow"></div>
<div class="nContainer">
<ul class="listContainer">
... ...
</ul>
</div>
<div class="downArrow"></div>
</div>
Be sure to change the CSS to match, and don't use inline JS, that's handled below.
Then the JavaScript becomes:
$(document).ready (init);
function init() {
//-- Activate click and focus handlers on the li elements.
$("ul.listContainer li > a").click ( function () { showPic (this); } )
// This next is IE only! use CSS.
.focus ( function () { this.hideFocus=true; } );
//-- Initialize the scroll controls for every list in an mContainer.
$("div.mContainer").each ( function (J) {
var jNode = $(this);
jNode.data ('OurScrollObject', new ListScroll (jNode) );
} );
}
/*--- ListScroll object. This lets us (1) avoid global variables, and (2) keep each
each list's data separate.
*/
function ListScroll ( contNode, //--Required: jQuery wrapper of the container node.
INIT_SCROLL_RATE, //--Optional: Initial rate of scrolling.
MAX_SCROLL_TICK, //--Optional: The maximum value of scrollTick before it's reset.
MIN_LIST_HEIGHT, //--Optional: Contracted height of the list.
REBOUND //--Optional: The value of scrollRate when we stop scrolling.
)
{
//--- Set constants to default values as needed.
var INIT_SCROLL_RATE = INIT_SCROLL_RATE || 8;
var MAX_SCROLL_TICK = MAX_SCROLL_TICK || 4;
var MIN_LIST_HEIGHT = MIN_LIST_HEIGHT || 145;
var REBOUND = REBOUND || 0;
var listHeight = contNode.find ("ul.listContainer").outerHeight (true);
var scrollUpLimit = MIN_LIST_HEIGHT - listHeight;
//--- Init state variables.
var currentTop = 0; // The current Y position of the UL.
var startTop = 0; // The starting top of the UL.
var scrollTick = 0; // Keeps track of how long we've scrolled so we can slow down accordingly.
var scrollRate = INIT_SCROLL_RATE;
var bGoDown = true; // Are we scrolling down?
var zInterval = null; // Tracks the animation, interval timer.
var bStopRequested = false;
//--- Apply onclick behaviors to the up/down arrow elements.
contNode.find (".upArrow, .downArrow").bind ("mousedown mouseup", scrollObjects);
//--- Set the list's visible height.
contNode.find (".nContainer").height (MIN_LIST_HEIGHT);
function scrollObjects (zEvent) //-- zEvent is sent to event listeners automatically.
{
var bClickUpBtn = $(this).hasClass ('upArrow');
var bMouseUp = (zEvent.type == 'mouseup');
/*--- Here are the states we want to act on:
1) Were we already scrolling this list?
2) Has the user signaled a desire to scroll (mousedown)?
3) Has the user signaled to scroll scrolling (mouseup)?
4) Has the user signaled to STOP RIGHT NOW, by clicking the opposite direction
from the scroll direction?
*/
if (bMouseUp && ! zInterval) {
//--- Already stopped before user released the mouse.
return;
}
if (! bMouseUp && zInterval && bGoDown != bClickUpBtn) {
//--- Already scrolling in the currently-commanded direction.
return;
}
if (zInterval) {
//--- Already scrolling
if (bMouseUp) {
//--- Soft stop commanded (can coast down).
bStopRequested = true;
}
else {
//--- User must clicked in the opposite direction of the current scroll.
stopScroll ();
return;
}
}
else {
//--- Not scrolling yet
if (bBoundsCheck (bClickUpBtn) ) {
//--- Don't scroll beyond the top or bottom of the list.
return;
}
bGoDown = ! bClickUpBtn;
zInterval = setInterval (scrollList, 20);
}
}
function bBoundsCheck (bGoingUp) {
/*--- Keeps the list from scrolling out of bounds.
returns true if clipping (would have) occured.
*/
if (bGoingUp && currentTop <= scrollUpLimit) {
currentTop = scrollUpLimit;
return true;
}
if ( ! bGoingUp && currentTop >= 0) {
currentTop = 0;
return true;
}
return false;
}
function stopScroll () {
//--- Resets the state variables and clears the animation timer.
clearInterval (zInterval);
zInterval = null;
startTop = currentTop;
scrollTick = 0;
scrollRate = INIT_SCROLL_RATE;
bStopRequested = false;
}
function scrollList () {
//--- Increment or decrement currentTop based on direction.
if (bGoDown) currentTop += scrollRate;
else currentTop -= scrollRate;
if (bBoundsCheck ( ! bGoDown) ) {
stopScroll ();
contNode.find (".listContainer").css ('top', currentTop + "px");
return;
}
contNode.find (".listContainer").css ('top', currentTop + "px");
scrollTick++;
//if (scrollTick >= MAX_SCROLL_TICK || bStopRequested) { NO! Not ergo.
if (bStopRequested) {
scrollRate--; // slow the scroll rate down for a little style
scrollTick = 0;
}
if (scrollRate <= REBOUND) {
// Scroll is finished. clear the interval and reset vars for the next scroll.
stopScroll ();
}
}
}
See it in action at jsFiddle.
Here's a handy jQuery Reference.
Update:
To change which arrow goes what direction, change this line:
var bClickUpBtn = $(this).hasClass ('upArrow');
To:
var bClickUpBtn = $(this).hasClass ('downArrow');
See the Fiddle.

Related

How to run multiple functions in JQuery?

Have two functions in my index.php file, they work fine, but will only execute the last one. They work fine when one is commented out or the order is swapped, my question is how can I get them to both run if this is possible.
// ************************* Scroll Up Button *************************
// Get the button
var mybutton = document.getElementById("scrollTopBtn");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()
console.log('Scroll To Top Button');
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
scrollTopBtn.style.display = "block";
} else {
scrollTopBtn.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
// ********************** Sticky navbar **********************************
window.onscroll = function() {stickyHeaderScroll()};
var header = document.getElementById("navBack");
var sticky = header.offsetTop;
function stickyHeaderScroll() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
For the example above the navbar will remain sticky but the scroll to top button won't appear, if I swap the code then scroll button will appear and work but navbar won't remain sticky. I've tried adding the sticky navbar code into the navbar.php, but still get the same problem.
I know I'm missing something really obvious here, but the other answers I've looked at don't seem to work.
You can add both function at once
// ************************* Scroll Up Button *************************
// Get the button
var mybutton = document.getElementById("scrollTopBtn");
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block"; // here was used worng object
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
// ********************** Sticky navbar **********************************
var header = document.getElementById("navBack");
var sticky = header.offsetTop;
function stickyHeaderScroll() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {
if(typeof scrollFunction === "function") {
scrollFunction();
}
if(typeof stickyHeaderScroll=== "function") {
stickyHeaderScroll();
}
console.log('Scroll To Top Button');
};
or use window.addEventListener('scroll', functionName)
window.addEventListener('scroll', scrollFunction);
window.addEventListener('scroll', stickyHeaderScroll);

How to add extra space to div using Jquery?

I am working on the sticky menu and highlight menu based on div id in WordPress. I have completed code well but I got a problem.
I have a sticky header when I click menu item in side sticky menu title going back to header title not visible.
I want result like this.'
How can I solve this?
My Jquery Code
jQuery(function($) {
/**
* This part causes smooth scrolling using scrollto.js
* We target all a tags inside the nav, and apply the scrollto.js to it.
*/
$("#nav a").click(function(evn){
evn.preventDefault();
$('html,body').scrollTo(this.hash, this.hash);
});
var aChildren = jQuery("#nav li").children(); // find the a children of the list items
var aArray = []; // create the empty aArray
for (var i=0; i < aChildren.length; i++) {
var aChild = aChildren[i];
var ahref = jQuery(aChild).attr('href');
console.log(ahref);
aArray.push(ahref);
} // this for loop fills the aArray with attribute href values
$(window).scroll(function(){
var windowPos = $(window).scrollTop()+70; // get the offset of the window from the top of page
console.log('Window Position:'+windowPos);
var windowHeight = $(window).height(); // get the height of the window
var docHeight = $(document).height();
for (var i=0; i < aArray.length; i++) {
var theID = aArray[i];
//console.log(theID);
var divPos = $(theID).offset().top-150; // get the offset of the div from the top of page
console.log('Div Position:'+divPos);
var divHeight = $(theID).height(); // get the height of the div in question
if (windowPos >= divPos && windowPos < (divPos + divHeight)) {
$("a[href='" + theID + "']").addClass("nav-active");
} else {
$("a[href='" + theID + "']").removeClass("nav-active");
}
}
if(windowPos + windowHeight == docHeight) {
if (!$("#nav li:last-child a").hasClass("nav-active")) {
var navActiveCurrent = $(".nav-active").attr("href");
$("a[href='" + navActiveCurrent + "']").removeClass("nav-active");
$("#nav li:last-child a").addClass("nav-active");
}
}
});
});
You need to offset the height of the heading when you jump to an anchored section.
Are you using the jQuery scrollTo plugin? If you can do something like:
$("#nav a").click(function(evn){
evn.preventDefault();
$('html,body').scrollTo(this.hash, 800, {offset: {top:-80, left:0} });
});
Options for scrollTo found here: http://demos.flesler.com/jquery/scrollTo/

Wordpress: page linking in single page project

i am trying to build a small single page wordpress theme, but struggling to find a way to make the navigation menu work.
The pages are loaded with this function: http://pastebin.com/Di5MhS8y . Each page is displayed as a section of my homepage, based on its menu_order.
If i make a custom menu voice linking outsite my website (tried with www.google.com) the menu works just fine.
Problems arise when i try to link to a single section of my website. The whole page gets reloaded and i'm brought back at the top of it.
I reckon i should maybe give a specific id to each section, and link to it, but i'm not sure. Any suggestion would be super appreciated!
The best way would be to give each section an ID.
if you want clean URLS you can create a function with Jquery
here's one i used in a one page website
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('html', 'body', 'document', 'window');
//console.log(scrollElem);
$('a[href*=#]').each(function() {
var thisPath = filterPath(this.pathname) || locationPath;
if ( locationPath == thisPath
&& (location.hostname == this.hostname || !this.hostname)
&& this.hash.replace(/#/,'') ) {
var $target = $(this.hash), target = this.hash;
if (target) {
//console.log('Target: ' + target + ' offset: ' + targetOffset);
$(this).click(function(event) {
var targetOffset = $target.offset().top;
event.preventDefault();
$(scrollElem).animate({scrollTop: targetOffset}, 1000, function() {
//console.log($(scrollElem).scrollTop());
location.hash = target;
$(scrollElem).animate({scrollTop: targetOffset}, 0);
});
});
}
}
});
// use the first element that is "scrollable"
function scrollableElement(els) {
for (var i = 0, argLength = arguments.length; i <argLength; i++) {
var el = arguments[i],
$scrollElement = $(el);
if ($scrollElement.scrollTop()> 0) {
return el;
} else {
$scrollElement.scrollTop(1);
var isScrollable = $scrollElement.scrollTop()> 0;
//console.log(el + ': ' + $scrollElement.scrollTop());
$scrollElement.scrollTop(0);
if (isScrollable) {
return el;
}
}
}
return 'body';
}

javascript triggers "onmouseover" and "onmouseout" when i hover the div in another div

I am working on a grid layout for my new website. The PHP code:
echo"<div class='model_container_invisible' onMouseOver='fade(this, 0)' onMouseOut='fade(this, 1)'>";
echo"<span class='model_title_wrapper'>";
echo"<span class='model_title'>Ancient Dragon</span>";
echo"<span class='model_designer'>designed by Kamiya Satoshi</span>";
echo"</span>";
echo"<img class='model_img' src='img/models/001.jpg' />";
echo"</div>";
this is for on grid element. the opacity of the image is 0.5, i want to change it when i hover the element with my js function fade(). here is its code:
function fade(elem, direction)
{
/* if(elem.className == "model_container_invisible")
elem.className = "model_container_visible";
else
elem.className = "model_container_invisible"; */
var img = elem.getElementsByTagName("img")[0]; //das Bild
if(direction == 0) //einblenden
{
alert("fadein, this: "+elem);
img.style.opacity = 0.5;
var aktiv = window.setInterval(function() {
img.style.opacity = String(Number(img.style.opacity) + .05);
if(Number(img.style.opacity) >= 1.0) {
window.clearInterval(aktiv);
}
}, 8);
}
else //ausblenden
{
alert("fadeout, this: "+elem);
img.style.opacity = 1;
var aktiv = window.setInterval(function() {
img.style.opacity = String(Number(img.style.opacity) - .05);
if(Number(img.style.opacity) <= 0.5) {
window.clearInterval(aktiv);
}
}, 16);
}
}
but when my mouse pointer moves from on div into another div (lets say from model_title_wrapper to model_titel), the function is called again. i dont get it!
can you please help me? thanks!
Use onmouseenter instead of onmouseover as the later will fire the event when hovering in child elements, while onmouseenter will not (the event will not bubble up).
See info about the onmouseenter/onmouseleave events that you should use:
http://www.quirksmode.org/js/events_mouse.html#mouseenter
This happens because of default JavaScript event bubbling concept. When some event occurs on an element (like in this case the model_title) the event bubbles up to the parent document element.
Since the parent div (model_container_invisible) has one event handler, it will be executed irrespective of where exactly inside the event has actually occurred.
So to avoid this issue, you should verify if the eventSource is actually model_container_invisible and perform required logic.
Following link might help you : http://www.javascripter.net/faq/eventtargetsrcelement.htm

image impression tracking using javascript and php

so I want to track image(banner) impressions for each image.
for example if one image is in header it should track the impression when the page is loaded but if the image is in footer it should only track it when user scrolls down to footer.
I can do the 1x1 pixel image to track it with php,but I think I need javascript as well,
in summary I want to track the image impression ONLY when the image is seen by user (not when page is loaded).
Any ideas ?
note: I've already searched and the questions only answer how to track impression on page load which is not what I'm looking for.
When the page loads, use javascript to:
Determine the location of the image with respect to the whole page
Detect the size of the user's browser window
If the image is in the viewport, run an ajax call to the tracking script
Add an onscroll event that detects if the image has been moved into the viewport... if so, run the ajax tracking script.
That should about do it. Just make sure that the javascript function that you use to call the tracking script can only be run once (set a global has_been_tracked variable to false, and have the script switch it to true when the tracking function runs)
you can see demo function tracking call impression
you detect axis scrolltop + screen window height > position top element Banner you send impression.
<body>
<div style="clear:both; height:1000px;"></div>
<div id="banner" style="clear:both; height:200px; background:#f00;">Test show</div>
<script language="javascript">
var windowPrototype={
wdHeight:function(){
var myHeight;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientHeight ) ) {
//IE 4 compatible
myHeight = document.body.clientHeight;
}
return myHeight;
},
wdWidth:function(){
var myWidth;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
} else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
} else if( document.body && ( document.body.clientWidth ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
}
return myWidth;
}
}
function getScrollTop(){
var ScrollTop = document.body.scrollTop;
if (ScrollTop == 0)
{
if (window.pageYOffset)
ScrollTop = window.pageYOffset;
else
ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
}
return ScrollTop;
}
function getElementTop(Elem) {
if(document.getElementById) {
var elem = document.getElementById(Elem);
} else if (document.all) {
var elem = document.all[Elem];
}
if(elem!=null){
yPos = elem.offsetTop;
tempEl = elem.offsetParent;
while (tempEl != null) {
yPos += tempEl.offsetTop;
tempEl = tempEl.offsetParent;
}
return yPos;
}
else{
return 0;
}
}
function tracking(){
var scrolltop=getScrollTop();
var advZoneTop=getElementTop('banner');
if((scrolltop+windowPrototype.wdHeight())>advZoneTop){
//send code tracking.
alert('send tracking code');
if(document.images){
var img=new Image();
img.src='http://logging.com/trackingbanner.jpg';
}
}else{
setTimeout('tracking()',100);
}
}
tracking();
//you can on scroll
/*
window.onscroll = function () {
// called when the window is scrolled.
var scrolltop=getScrollTop();
var advZoneTop=getElementTop('banner');
if((scrolltop+windowPrototype.wdHeight())>advZoneTop){
//send code tracking.
alert('send tracking code');
if(document.images){
var img=new Image();
img.src='http://logging.com/trackingbanner.jpg';
}
}
} */
</script>
</body>
</html>
I do understand your question. However, this is a VERY complex problem! To simplify, you should approach this with the following mindset: "How many impressions on the header image" (pure impressions tracked in PHP) + "How many user scrolled down do view an ad" (only tracked with javascript).
I've upvoted Ben, because he is 100% right on the following: to calculate the scrolled ad as being "seen" you will have to calculate screen dimensions + scroll value - image position, to see if the ad is being tracked. If you do not include "impressions" on the header you are crazy, because people like ME are running no script and will not register the original pageview, or the scroll.
The most efficient means of tracking is by "impressions" and/or "conversions" because they do not rely on the users OS, browser, and browsing habits to determine profitability. A combined effort of basic PHP and intermediate JS are required.
http://patik.com/blog/within-viewport-javascript-and-jquery-plugin/
The link above is to a script which will trigger an event when an element (particular image on your case) is entirely within the viewport.
On the footer image being in full view you could chose to track these events in Google Analytics or AJAX to call a PHP script should you have your own custom tracking count.

Categories