Subversion-Projekte lars-tiefland.zeldi.de

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
2 lars 1
// ####################################################################################
2
// #######                                                                      #######
3
// ####### Plugin:      jScroll                                                 #######
4
// ####### Author:      William Duffy                                           #######
5
// ####### Website:     http://www.wduffy.co.uk/jScroll                         #######
6
// ####### Version:     1.1	                                                    #######
7
// #######                                                                      #######
8
// ####### Copyright (c) 2011, William Duffy - www.wduffy.co.uk                 #######
9
// #######                                                                      #######
10
// ####### Permission is hereby granted, free of charge, to any person          #######
11
// ####### obtaining a copy of this software and associated documentation       #######
12
// ####### files (the "Software"), to deal in the Software without              #######
13
// ####### restriction, including without limitation the rights to use,         #######
14
// ####### copy, modify, merge, publish, distribute, sublicense, and/or sell    #######
15
// ####### copies of the Software, and to permit persons to whom the            #######
16
// ####### Software is furnished to do so, subject to the following             #######
17
// ####### conditions:                                                          #######
18
// #######                                                                      #######
19
// ####### The above copyright notice and this permission notice shall be       #######
20
// ####### included in all copies or substantial portions of the Software.      #######
21
// #######                                                                      #######
22
// ####### THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,      #######
23
// ####### EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES      #######
24
// ####### OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND             #######
25
// ####### NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT          #######
26
// ####### HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,         #######
27
// ####### WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING         #######
28
// ####### FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR        #######
29
// ####### OTHER DEALINGS IN THE SOFTWARE.                                      #######
30
// #######                                                                      #######
31
// ####################################################################################
32
(function($) {
33
 
34
    // Public: jScroll Plugin
35
    $.fn.jScroll = function(options) {
36
 
37
        var opts = $.extend({}, $.fn.jScroll.defaults, options);
38
 
39
        return this.each(function() {
40
			var $element = $(this);
41
			var $window = $(window);
42
			var locator = new location($element);
43
 
44
 
45
 
46
			$window.scroll(function() {
47
				$element
48
					.stop()
49
					.animate(locator.getMargin($window), opts.speed);
50
 
51
 
52
			});
53
        });
54
 
55
		// Private
56
		function location($element)
57
		{
58
 
59
			this.min = $element.offset().top;
60
			this.originalMargin = parseInt($element.css("margin-top"), 10) || 0;
61
 
62
			this.getMargin = function ($window)
63
			{
64
				var max = $element.parent().height() - $element.outerHeight();
65
				var margin = this.originalMargin;
66
 
67
				if ($window.scrollTop() >= this.min)
68
					margin = margin + opts.top + $window.scrollTop() - this.min;
69
 
70
				if (margin > max)
71
					margin = max;
72
 
73
				return ({"marginTop" : margin + 'px'});
74
			}
75
		}
76
 
77
    };
78
 
79
    // Public: Default values
80
    $.fn.jScroll.defaults = {
81
        speed	:	"slow",
82
		top		:	10
83
    };
84
 
85
})(jQuery);