2 * Interface Elements for jQuery
5 * http://interface.eyecon.ro
7 * Copyright (c) 2006 Stefan Petre
8 * Dual licensed under the MIT (MIT-LICENSE.txt)
9 * and GPL (GPL-LICENSE.txt) licenses.
14 * Applies a scrolling effect to document until the element gets into viewport
20 * @description scrolls the document until the lement gets into viewport
21 * @param Mixed speed animation speed, integer for miliseconds, string ['slow' | 'normal' | 'fast']
22 * @param String axis (optional) whatever to scroll on vertical, horizontal or both axis ['vertical'|'horizontal'|null]
23 * @param String easing (optional) The name of the easing effect that you want to use.
25 * @cat Plugins/Interface
26 * @author Stefan Petre
28 ScrollTo : function(speed, axis, easing) {
29 o = jQuery.speed(speed);
30 return this.queue('interfaceFX',function(){
31 new jQuery.fx.ScrollTo(this, o, axis, easing);
35 * @name ScrollToAnchors
36 * @description all links to '#elementId' will animate scroll
37 * @param Mixed speed animation speed, integer for miliseconds, string ['slow' | 'normal' | 'fast']
38 * @param String axis (optional) whatever to scroll on vertical, horizontal or both axis ['vertical'|'horizontal'|null]
39 * @param String easing (optional) The name of the easing effect that you want to use.
41 * @cat Plugins/Interface
42 * @author Stefan Petre
44 /*inspired by David Maciejewski www.macx.de*/
45 ScrollToAnchors : function(speed, axis, easing) {
49 jQuery('a[@href*="#"]', this).click(
52 parts = this.href.split('#');
53 jQuery('#' + parts[1]).ScrollTo(speed, axis, easing);
63 jQuery.fx.ScrollTo = function (e, o, axis, easing)
68 z.axis = /vertical|horizontal/.test(axis) ? axis : false;
70 p = jQuery.iUtil.getPosition(e);
71 s = jQuery.iUtil.getScroll();
72 z.clear = function(){clearInterval(z.timer);z.timer=null;jQuery.dequeue(z.e, 'interfaceFX');};
73 z.t=(new Date).getTime();
74 s.h = s.h > s.ih ? (s.h - s.ih) : s.h;
75 s.w = s.w > s.iw ? (s.w - s.iw) : s.w;
76 z.endTop = p.y > s.h ? s.h : p.y;
77 z.endLeft = p.x > s.w ? s.w : p.x;
81 var t = (new Date).getTime();
83 var p = n / z.o.duration;
84 if (t >= z.o.duration+z.t) {
86 setTimeout(function(){z.scroll(z.endTop, z.endLeft)},13);
88 if (!z.axis || z.axis == 'vertical') {
89 if (!jQuery.easing || !jQuery.easing[z.easing]) {
90 st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.endTop-z.startTop) + z.startTop;
92 st = jQuery.easing[z.easing](p, n, z.startTop, (z.endTop - z.startTop), z.o.duration);
97 if (!z.axis || z.axis == 'horizontal') {
98 if (!jQuery.easing || !jQuery.easing[z.easing]) {
99 sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.endLeft-z.startLeft) + z.startLeft;
101 sl = jQuery.easing[z.easing](p, n, z.startLeft, (z.endLeft - z.startLeft), z.o.duration);
109 z.scroll = function (t, l){window.scrollTo(l, t);};
110 z.timer=setInterval(function(){z.step();},13);