overlib_followscroll_mini.js 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //\/////
  2. //\ overLIB Follow Scroll Plugin
  3. //\ This file requires overLIB 4.10 or later.
  4. //\
  5. //\ overLIB 4.10 - You may not remove or change this notice.
  6. //\ Copyright Erik Bosrup 1998-2004. All rights reserved.
  7. //\ Contributors are listed on the homepage.
  8. //\ See http://www.bosrup.com/web/overlib/ for details.
  9. //\/////
  10. //\ THIS IS A VERY MODIFIED VERSION. DO NOT EDIT OR PUBLISH. GET THE ORIGINAL!
  11. if(typeof olInfo=='undefined'||typeof olInfo.meets=='undefined'||!olInfo.meets(4.10))alert('overLIB 4.10 or later is required for the Follow Scroll Plugin.');else{registerCommands('followscroll,followscrollrefresh');
  12. if(typeof ol_followscroll=='undefined')var ol_followscroll=0;if(typeof ol_followscrollrefresh=='undefined')var ol_followscrollrefresh=100;
  13. var o3_followscroll=0,o3_followscrollrefresh=100;
  14. function setScrollVariables(){o3_followscroll=ol_followscroll;o3_followscrollrefresh=ol_followscrollrefresh;}
  15. function parseScrollExtras(pf,i,ar){var k=i,v;if(k<ar.length){if(ar[k]==FOLLOWSCROLL){eval(pf+'followscroll=('+pf+'followscroll==0)?1:0');return k;}
  16. if(ar[k]==FOLLOWSCROLLREFRESH){eval(pf+'followscrollrefresh='+ar[++k]);return k;}}
  17. return-1;}
  18. function scroll_placeLayer(){var placeX,placeY,widthFix=0;
  19. if(o3_frame.innerWidth){widthFix=Math.ceil(1.2*(o3_frame.outerWidth-o3_frame.innerWidth));widthFix=(widthFix>50)?20:widthFix;iwidth=o3_frame.innerWidth;}else if(eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientWidth=='number'")&&eval('o3_frame.'+docRoot+'.clientWidth'))
  20. iwidth=eval('o3_frame.'+docRoot+'.clientWidth');
  21. winoffset=(olIe4)?eval('o3_frame.'+docRoot+'.scrollLeft'):o3_frame.pageXOffset;
  22. placeX=runHook('horizontalPlacement',FCHAIN,iwidth,winoffset,widthFix);
  23. if(o3_frame.innerHeight)iheight=o3_frame.innerHeight;else if(eval('o3_frame.'+docRoot)&&eval("typeof o3_frame."+docRoot+".clientHeight=='number'")&&eval('o3_frame.'+docRoot+'.clientHeight'))
  24. iheight=eval('o3_frame.'+docRoot+'.clientHeight');
  25. scrolloffset=(olIe4)?eval('o3_frame.'+docRoot+'.scrollTop'):o3_frame.pageYOffset;
  26. placeY=runHook('verticalPlacement',FCHAIN,iheight,scrolloffset);
  27. repositionTo(over,placeX,placeY);
  28. if(o3_followscroll&&o3_sticky&&(o3_relx||o3_rely)&&(typeof o3_draggable=='undefined'||!o3_draggable)){if(typeof over.scroller=='undefined'||over.scroller.canScroll)over.scroller=new Scroller(placeX-winoffset,placeY-scrolloffset,o3_followscrollrefresh);}}
  29. function Scroller(X,Y,refresh){this.canScroll=0;this.refresh=refresh;this.x=X;this.y=Y;this.timer=setTimeout("repositionOver()",this.refresh);}
  30. function cancelScroll(){if(!o3_followscroll||typeof over.scroller=='undefined')return;over.scroller.canScroll=1;
  31. if(over.scroller.timer){clearTimeout(over.scroller.timer);over.scroller.timer=null;}}
  32. function getPageScrollY(){if(o3_frame.pageYOffset)return o3_frame.pageYOffset;if(eval(docRoot))return eval('o3_frame.'+docRoot+'.scrollTop');return-1;}
  33. function getPageScrollX(){if(o3_frame.pageXOffset)return o3_frame.pageXOffset;if(eval(docRoot))return eval('o3_frame.'+docRoot+'.scrollLeft');return-1;}
  34. function getLayerTop(layer){if(layer.pageY)return layer.pageY;if(layer.style.top)return parseInt(layer.style.top);return-1;}
  35. function getLayerLeft(layer){if(layer.pageX)return layer.pageX;if(layer.style.left)return parseInt(layer.style.left);return-1;}
  36. function repositionOver(){var X,Y,pgLeft,pgTop;pgTop=getPageScrollY();pgLeft=getPageScrollX();X=getLayerLeft(over)-pgLeft;Y=getLayerTop(over)-pgTop;
  37. if(X!=over.scroller.x||Y!=over.scroller.y)repositionTo(over,pgLeft+over.scroller.x,pgTop+over.scroller.y);over.scroller.timer=setTimeout("repositionOver()",over.scroller.refresh);}
  38. registerRunTimeFunction(setScrollVariables);registerCmdLineFunction(parseScrollExtras);registerHook("hideObject",cancelScroll,FAFTER);registerHook("placeLayer",scroll_placeLayer,FREPLACE);if(olInfo.meets(4.10))registerNoParameterCommands('followscroll');}