1 | /* ========================================================= |
---|
2 | |
---|
3 | // jquery.innerfade.js |
---|
4 | |
---|
5 | // Datum: 2007-01-29 |
---|
6 | // Firma: Medienfreunde Hofmann & Baldes GbR |
---|
7 | // Autor: Torsten Baldes |
---|
8 | // Mail: t.baldes@medienfreunde.com |
---|
9 | // Web: http://medienfreunde.com |
---|
10 | |
---|
11 | // based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/ |
---|
12 | |
---|
13 | // ========================================================= */ |
---|
14 | // jquery.animated.innerfade.js |
---|
15 | |
---|
16 | // Datum: 2007-10-30 |
---|
17 | // Firma: OpenStudio |
---|
18 | // Autor: Arnault PACHOT |
---|
19 | // Mail: apachot@openstudio.fr |
---|
20 | // Web: http://www.openstudio.fr |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | (function($) { |
---|
26 | |
---|
27 | $.fn.animatedinnerfade = function(options) { |
---|
28 | var mytimer; |
---|
29 | var pauseActivated=false; |
---|
30 | this.each(function(){ |
---|
31 | var settings = { |
---|
32 | animationtype: 'fade', |
---|
33 | speed: 'normal', |
---|
34 | timeout: 15000, |
---|
35 | type: 'sequence', |
---|
36 | containerheight: '300px', |
---|
37 | containerwidth: '600px', |
---|
38 | runningclass: 'innerfade', |
---|
39 | animationSpeed: 15000, |
---|
40 | bgFrame: 'none', |
---|
41 | controlButtonsPath: 'img', |
---|
42 | controlBox: 'none', |
---|
43 | controlBoxClass: 'none', |
---|
44 | displayTitle: 'none', |
---|
45 | titleClass: 'innerfade-title' |
---|
46 | }; |
---|
47 | |
---|
48 | if(options) |
---|
49 | $.extend(settings, options); |
---|
50 | |
---|
51 | var elements = $(this).children(); |
---|
52 | |
---|
53 | if (settings.displayTitle != 'none') |
---|
54 | $(this).append("<div class='"+settings.titleClass+"'><h2>"+$(elements[0]).find("a:first img").attr("title")+"</h2></div>"); |
---|
55 | |
---|
56 | if (settings.bgFrame != 'none') |
---|
57 | { |
---|
58 | $(this).append("<div class='bg-frame'><a href='"+$(elements[0]).find("a:first").attr("href")+"'><img src='"+settings.bgFrame+"' width='"+settings.containerwidth+"' height='"+settings.containerheight+"'/></a></div>"); |
---|
59 | $(this).find(".bg-frame").css('position', 'absolute').css('top', 0).css('left', 0).css('z-index', 300).css('height', settings.containerheight).css('width', settings.containerwidth); |
---|
60 | } |
---|
61 | if (settings.controlBox != 'none') |
---|
62 | { |
---|
63 | $(this).bind('mouseover', function(){$(this).find(".control-panel").show();}); |
---|
64 | $(this).bind('mouseout', function(){$(this).find(".control-panel").hide();}); |
---|
65 | /* |
---|
66 | $(this).append("<div class='"+settings.controlBoxclass+" control-panel'><a class='back-button' href='#'><img src='"+settings.controlButtonsPath+"/previous.gif' alt='previous' /></a> <a class='pause-button' href='#'><img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' /></a> <a class='next-button' href='#'><img src='"+settings.controlButtonsPath+"/next.gif' alt='next' /></a></div>"); |
---|
67 | */ |
---|
68 | $(this).append("<div class='"+settings.controlBoxclass+" control-panel'> <a class='back-button' href='#'><img src='"+settings.controlButtonsPath+"/previous.gif' alt='previous' /></a> <a class='pause-button' href='#'><img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' /></a> </div>"); |
---|
69 | $(this).find(".control-panel").hide(); |
---|
70 | $(this).find(".control-panel").css('z-index', 350).css('position', 'absolute'); |
---|
71 | if (settings.controlBoxClass == 'none') |
---|
72 | $(".control-panel").css('right', '10px').css('top', '5px').css('textAlign', 'right').css('margin', 0).css('paddingTop', '0').css('marginRight', '0').css('fontSize', '20px').css('color', '#88d300'); |
---|
73 | |
---|
74 | $(this).find(".control-panel a.next-button").bind('click', function(){pauseActivated = false; clearTimeout(mytimer); $(".control-panel a.pause-button").html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' />"); $.animatedinnerfade.next(elements, settings, 1, 0, mytimer, pauseActivated);return false;}); |
---|
75 | $(this).find(".control-panel a.back-button").bind('click', function(){pauseActivated = false; clearTimeout(mytimer); $(".control-panel a.pause-button").html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' />"); $.animatedinnerfade.next(elements, settings, elements.length - 1, 0, mytimer, pauseActivated);return false;}); |
---|
76 | $(this).find(".control-panel a.pause-button").bind('click', function(){ |
---|
77 | clearTimeout(mytimer); |
---|
78 | if (!pauseActivated){ |
---|
79 | pauseActivated = true; |
---|
80 | $(this).html("<img src='"+settings.controlButtonsPath+"/play.gif' alt='play' />"); |
---|
81 | $(elements[0]).stop().stop(); |
---|
82 | }else { |
---|
83 | pauseActivated = false; |
---|
84 | $(this).html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' />"); |
---|
85 | var vwidth = - (parseInt($(elements[0]).find("img").attr("width"))-parseInt(settings.containerwidth)); |
---|
86 | if (vwidth > 0) vwidth = 0; |
---|
87 | var duree = parseInt(settings.timeout) - parseInt((parseInt($(elements[0]).css('left')) / parseInt(vwidth)) * parseInt(settings.timeout)); |
---|
88 | $(elements[0]).animate({top: 0, left: vwidth}, duree); |
---|
89 | mytimer = setTimeout(function(){ |
---|
90 | $.animatedinnerfade.next(elements, settings, 1, 0, mytimer, pauseActivated); |
---|
91 | }, duree); |
---|
92 | } |
---|
93 | return false; |
---|
94 | }); |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | if (elements.length > 1) { |
---|
99 | |
---|
100 | $(this).css('position', 'relative').css('overflow', 'hidden').css('height', settings.containerheight).css('width', settings.containerwidth); |
---|
101 | |
---|
102 | $(this).addClass(settings.runningclass); |
---|
103 | |
---|
104 | for ( var i = 0; i < elements.length; i++ ) { |
---|
105 | $(elements[i]).css('position', 'absolute').css('top', 0).css('left', 0).css('z-index', String(elements.length-i)); |
---|
106 | $(elements[i]).hide(); |
---|
107 | }; |
---|
108 | $(elements[0]).css('top', 0); |
---|
109 | $(elements[0]).css('left', 0); |
---|
110 | |
---|
111 | $.animatedinnerfade.move_photo(elements[0], settings); |
---|
112 | |
---|
113 | if ( settings.type == 'sequence' ) { |
---|
114 | mytimer = setTimeout(function(){ |
---|
115 | $.animatedinnerfade.next(elements, settings, 1, 0, mytimer, pauseActivated); |
---|
116 | }, settings.timeout); |
---|
117 | |
---|
118 | } |
---|
119 | else { |
---|
120 | var nextrandom; |
---|
121 | do { nextrandom = Math.floor ( Math.random ( ) * ( elements.length ) ); } while ( nextrandom == 0 ) |
---|
122 | mytimer = setTimeout((function(){$.animatedinnerfade.next(elements, settings, nextrandom, 0, mytimer, pauseActivated);}), settings.timeout); |
---|
123 | |
---|
124 | } |
---|
125 | $(elements[0]).show(); |
---|
126 | } |
---|
127 | |
---|
128 | }); |
---|
129 | }; |
---|
130 | |
---|
131 | |
---|
132 | $.animatedinnerfade = function() {} |
---|
133 | $.animatedinnerfade.next = function (elements, settings, current, last, mytimer, pauseActivated) { |
---|
134 | clearTimeout(mytimer); |
---|
135 | |
---|
136 | var next, prev; |
---|
137 | if (current == (elements.length - 1)) |
---|
138 | next = 0; |
---|
139 | else |
---|
140 | next = current+1; |
---|
141 | |
---|
142 | if (current == 0) |
---|
143 | prev = elements.length - 1; |
---|
144 | else |
---|
145 | prev = current - 1; |
---|
146 | |
---|
147 | for ( var i = 0; i < elements.length; i++ ) { |
---|
148 | if ((i != last) && (i != current)) |
---|
149 | { |
---|
150 | $(elements[i]).css('z-index', '1'); |
---|
151 | $(elements[i]).hide(); |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | $(elements[last]).css('z-index', '190'); |
---|
156 | $(elements[current]).css('z-index', '195'); |
---|
157 | |
---|
158 | if (settings.displayTitle != 'none') |
---|
159 | $("."+settings.titleClass+" h2").html($(elements[current]).find("a:first img").attr("title")); |
---|
160 | |
---|
161 | if (settings.controlBox != 'none') |
---|
162 | { |
---|
163 | $(this).find(".control-panel a.next-button").unbind('click'); $(".control-panel a.next-button").bind('click', function(){pauseActivated = false;clearTimeout(mytimer);$(".control-panel a.pause-button").html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' />"); $.animatedinnerfade.next(elements, settings, next, current, mytimer, pauseActivated);return false;}); |
---|
164 | $(this).find(".control-panel a.back-button").unbind('click'); $(".control-panel a.back-button").bind('click', function(){pauseActivated = false; clearTimeout(mytimer);$(".control-panel a.pause-button").html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' />"); $.animatedinnerfade.next(elements, settings, prev, current, mytimer, pauseActivated);return false;}); |
---|
165 | $(this).find(".control-panel a.pause-button").unbind('click');$(".control-panel a.pause-button").bind('click', function(){ |
---|
166 | clearTimeout(mytimer); |
---|
167 | if (!pauseActivated){ |
---|
168 | pauseActivated = true; |
---|
169 | $(this).html("<img src='"+settings.controlButtonsPath+"/play.gif' alt='play' />"); $(elements[current]).stop().stop(); |
---|
170 | }else{ |
---|
171 | pauseActivated = false; |
---|
172 | $(this).html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' />"); |
---|
173 | var vwidth = - (parseInt($(elements[current]).find("img").attr("width"))-parseInt(settings.containerwidth)); |
---|
174 | if (vwidth > 0) vwidth = 0; |
---|
175 | var duree = parseInt(settings.timeout) - parseInt((parseInt($(elements[current]).css('left')) / parseInt(vwidth)) * parseInt(settings.timeout)); |
---|
176 | $(elements[current]).animate({top: 0, left: vwidth}, duree); |
---|
177 | mytimer = setTimeout((function(){$.animatedinnerfade.next(elements, settings, next, current, mytimer, pauseActivated);}), duree); |
---|
178 | } |
---|
179 | return false; |
---|
180 | }); |
---|
181 | } |
---|
182 | if (settings.bgFrame != 'none') |
---|
183 | $(this).find(".bg-frame a").attr("href", $(elements[current]).find("a:first").attr("href")); |
---|
184 | |
---|
185 | $(elements[current]).css('top', 0).css('left', 0); |
---|
186 | if ( settings.animationtype == 'slide' ) { |
---|
187 | $(elements[last]).slideUp(settings.speed, $(elements[current]).slideDown(settings.speed)); |
---|
188 | } else if ( settings.animationtype == 'fade' ) { |
---|
189 | $(elements[last]).fadeOut(settings.speed); |
---|
190 | $(elements[current]).fadeIn(settings.speed); |
---|
191 | } else { |
---|
192 | alert('animationtype must either be \'slide\' or \'fade\''); |
---|
193 | }; |
---|
194 | |
---|
195 | $.animatedinnerfade.move_photo(elements[current], settings); |
---|
196 | |
---|
197 | if ( settings.type == 'sequence' ) { |
---|
198 | mytimer = setTimeout((function(){$.animatedinnerfade.next(elements, settings, next, current, mytimer, pauseActivated);}), settings.timeout); |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | var nextrandom; |
---|
203 | do { nextrandom = Math.floor ( Math.random ( ) * ( elements.length ) ); } while ( nextrandom == current ) |
---|
204 | mytimer = setTimeout((function(){$.animatedinnerfade.next(elements, settings, nextrandom, current, mytimer, pauseActivated);}), settings.timeout); |
---|
205 | } |
---|
206 | |
---|
207 | }; |
---|
208 | |
---|
209 | $.animatedinnerfade.move_photo = function (element, settings) { |
---|
210 | |
---|
211 | var vheight = - (parseInt($(element).find("img").attr("height"))-parseInt(settings.containerheight)); |
---|
212 | var vwidth = - (parseInt($(element).find("img").attr("width"))-parseInt(settings.containerwidth)); |
---|
213 | if (vheight > 0) vheight = 0; |
---|
214 | if (vwidth > 0) vwidth = 0; |
---|
215 | $(element).animate({top: vheight, left: parseInt(vwidth/2)}, parseInt(settings.animationSpeed/2)).animate({top: 0, left: vwidth}, parseInt(settings.animationSpeed/2)); |
---|
216 | }; |
---|
217 | |
---|
218 | })(jQuery); |
---|
219 | |
---|