[7862] | 1 | // JavaScript Document |
---|
| 2 | |
---|
| 3 | //pAnchor plugin for piwigo - ease to anchor javascript functions (uses jquery) |
---|
| 4 | $(document).ready(function() { |
---|
| 5 | //check for pAnchor anchor - name of anchor can be customized in main.inc.php |
---|
| 6 | if ($('#pAnchor').attr('name')) { |
---|
| 7 | //alert('pAnchor exists'); |
---|
| 8 | var url = window.location.href; |
---|
| 9 | if (url.indexOf('#') == -1) { |
---|
| 10 | //defaut values a=0.20, t=16 and delay=250 |
---|
| 11 | easeToInit('pAnchor', 0.20, 16, 250); |
---|
| 12 | } |
---|
| 13 | } |
---|
| 14 | }); |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | function easeTo(yDest, yTemp, a, t) { |
---|
| 18 | //easeTo function to scroll from 0 to yDest. X will scroll to 0 also. |
---|
| 19 | //yDest is y value of destination |
---|
| 20 | //YTemp is temp value as scroll progresses to yDest |
---|
| 21 | //a = a || 0.2; //about 0.2 |
---|
| 22 | //t = t || 20; //about 15-20 milliseconds |
---|
| 23 | |
---|
| 24 | var x1 = 0; |
---|
| 25 | var y1 = 0; |
---|
| 26 | var x2 = 0; |
---|
| 27 | var y2 = 0; |
---|
| 28 | var x3 = 0; |
---|
| 29 | var y3 = 0; |
---|
| 30 | |
---|
| 31 | if (document.documentElement) { |
---|
| 32 | x1 = document.documentElement.scrollLeft || 0; |
---|
| 33 | y1 = document.documentElement.scrollTop || 0; |
---|
| 34 | } |
---|
| 35 | if (document.body) { |
---|
| 36 | x2 = document.body.scrollLeft || 0; |
---|
| 37 | y2 = document.body.scrollTop || 0; |
---|
| 38 | } |
---|
| 39 | x3 = window.scrollX || 0; |
---|
| 40 | y3 = window.scrollY || 0; |
---|
| 41 | |
---|
| 42 | var x = Math.max(x1, Math.max(x2, x3)); |
---|
| 43 | var y = Math.max(y1, Math.max(y2, y3)); |
---|
| 44 | |
---|
| 45 | var speed = 1 + a; |
---|
| 46 | var yTemp = Math.floor(yTemp / speed); |
---|
| 47 | window.scrollTo(Math.floor(x / speed), yDest - yTemp); |
---|
| 48 | if(x > 0 || yTemp > 1) { |
---|
| 49 | var f = "easeTo(" + yDest + ", " + yTemp + ", " + a + ", " + t + ")"; |
---|
| 50 | //alert(f); |
---|
| 51 | window.setTimeout(f, t); |
---|
| 52 | } else { |
---|
| 53 | //alert('done'); |
---|
| 54 | } |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | function easeToInit(elem, a, t, delay){ |
---|
| 58 | //easeToInit initializes and easeTo operation |
---|
| 59 | //elem is id of document element, a is psuedo-acceleration, t is timer for interative calls |
---|
| 60 | //delay is just a small time delay before easeTo actually begins. give the page a chance to be static before |
---|
| 61 | //easeTo the desired element. The position can be fined with params in the main.inc.php file. |
---|
| 62 | //ALSO NOTE: DIFFERENT BROWSERS WILL YEILDLY SLIGHLY DIFFERENT RESULTS, but typically within a few pixels. |
---|
| 63 | y = document.getElementById(elem).offsetTop; |
---|
| 64 | var f = "easeTo(" + y + ", " + y + ", " + a + ", " + t + ")"; |
---|
| 65 | window.setTimeout(f, delay); |
---|
| 66 | } |
---|
| 67 | |
---|