// JavaScript Document //pAnchor plugin for piwigo - ease to anchor javascript functions (uses jquery) $(document).ready(function() { //check for pAnchor anchor - name of anchor can be customized in main.inc.php if ($('#pAnchor').attr('name')) { //alert('pAnchor exists'); var url = window.location.href; if (url.indexOf('#') == -1) { //defaut values a=0.20, t=16 and delay=250 easeToInit('pAnchor', 0.20, 16, 250); } } }); function easeTo(yDest, yTemp, a, t) { //easeTo function to scroll from 0 to yDest. X will scroll to 0 also. //yDest is y value of destination //YTemp is temp value as scroll progresses to yDest //a = a || 0.2; //about 0.2 //t = t || 20; //about 15-20 milliseconds var x1 = 0; var y1 = 0; var x2 = 0; var y2 = 0; var x3 = 0; var y3 = 0; if (document.documentElement) { x1 = document.documentElement.scrollLeft || 0; y1 = document.documentElement.scrollTop || 0; } if (document.body) { x2 = document.body.scrollLeft || 0; y2 = document.body.scrollTop || 0; } x3 = window.scrollX || 0; y3 = window.scrollY || 0; var x = Math.max(x1, Math.max(x2, x3)); var y = Math.max(y1, Math.max(y2, y3)); var speed = 1 + a; var yTemp = Math.floor(yTemp / speed); window.scrollTo(Math.floor(x / speed), yDest - yTemp); if(x > 0 || yTemp > 1) { var f = "easeTo(" + yDest + ", " + yTemp + ", " + a + ", " + t + ")"; //alert(f); window.setTimeout(f, t); } else { //alert('done'); } } function easeToInit(elem, a, t, delay){ //easeToInit initializes and easeTo operation //elem is id of document element, a is psuedo-acceleration, t is timer for interative calls //delay is just a small time delay before easeTo actually begins. give the page a chance to be static before //easeTo the desired element. The position can be fined with params in the main.inc.php file. //ALSO NOTE: DIFFERENT BROWSERS WILL YEILDLY SLIGHLY DIFFERENT RESULTS, but typically within a few pixels. y = document.getElementById(elem).offsetTop; var f = "easeTo(" + y + ", " + y + ", " + a + ", " + t + ")"; window.setTimeout(f, delay); }