// ***************************************************************************** // ** TableFloaterTitle.js // ** // ** Unobtrusive JavaScript function which will keep the titles of a table on // ** screen as the user scrolls down. The titles will 'float' keeping in view // ** as long as any part of the table remains in view. // ** // ** Author: Stan Slaughter // ** Date: 07/23/2008 // ** E-mail: Stan_Slaughter@Yahoo.Com // ** Web: http://www.StanSight.Com/ // ***************************************************************************** ////////////////////////////////////////////////////////////////////////////// // startFloatTitle - Start tables floating // // This function will scan the page looking for every "table" on it. // Any table which has a class of "FloatTitle" will have its ID value // passed on to the function for the actual float process ////////////////////////////////////////////////////////////////////////////// function startFloatTitle() { var cnt=0; var allTableIDs = new Array(); allTables = document.getElementsByTagName("table"); // Scan page for all tables with a class of "FloatTitle" for (i=0;i0) ? document.documentElement.scrollTop : document.body.scrollTop; if (newTop < startTop) newTop = startTop; if (newTop > endTop) newTop = endTop; // Move the title to new postion var titleObj = document.getElementById(titleID); if (newTop > startTop && newTop < endTop) { // Display "Title" if it is not all ready being displayed if (titleObj.style.display != 'block') titleObj.style.display='block'; // Apply offset to get newTop position newTop = newTop + startOffsetTop; // Apply Ease-In effect easeInWanted=true; if (easeInWanted) { // Get current location and get the difference from where it's // at to where you want it to go oldTop = parseInt(titleObj.style.top); topDiff=newTop-oldTop; // Calaculate how far you want to move it - then set that to new postion moveTop=0; if ( (topDiff < (-1) ) || (topDiff > (1) ) ) { moveTop=Math.round(topDiff/3);} newTop = oldTop + moveTop; } // Move to new top position if (newTop < 0) newTop = 0; titleObj.style.top = newTop + "px"; } else { // Else hide "Title" if it is not all ready hidden if (titleObj.style.display != 'none') { titleObj.style.display='none'; titleObj.style.top = "0px"; titleObj.style.zIndex="1"; } } } // Execute this function again in 40 milliseconds (thousandths of a second) cmd = "floatTitleLoop('" + tableID + "','" + titleID + "','" + cnt + "')"; floatTitleTimer[cnt] = window.setTimeout(cmd, 40); } ////////////////////////////////////////////////////////////////////////////// // FindPosition - find the Top and Left postion of an object on the page // @param obj - object of element whose position needs to be found // @return array - Array whoose first eleemnt is the left postion and whoose // second is the top position ////////////////////////////////////////////////////////////////////////////// function FindPosition(obj) { // Figure out where the obj object is in the page by adding // up all the offsets for all the containing parent objects if (obj == null) return [0,0]; // Assign the obj object to a temp variable tmpObj = obj; // Get the offsets for the current object var obj_left = tmpObj.offsetLeft; var obj_top = tmpObj.offsetTop; // If the current object has a parent (ie contained in a table, div, etc..) if (tmpObj.offsetParent) { // Loop through all the parents and add up their offsets // The while loop will end when no more parents exist and a null is returned while (tmpObj = tmpObj.offsetParent) { obj_left += tmpObj.offsetLeft; obj_top += tmpObj.offsetTop; } } return [obj_left , obj_top]; } ////////////////////////////////////////////////////////////////////////////// // Start floating titles after window finishes loading ////////////////////////////////////////////////////////////////////////////// window.onload = startFloatTitle; ////////////////////////////////////////////////////////////////////////////// // Start floating titles when window is resized ////////////////////////////////////////////////////////////////////////////// window.onresize = startFloatTitle;