aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'uucky.me/Uucky的小站_files/jquery.swatchbook.js')
-rw-r--r--uucky.me/Uucky的小站_files/jquery.swatchbook.js249
1 files changed, 249 insertions, 0 deletions
diff --git a/uucky.me/Uucky的小站_files/jquery.swatchbook.js b/uucky.me/Uucky的小站_files/jquery.swatchbook.js
new file mode 100644
index 0000000..294b3f4
--- /dev/null
+++ b/uucky.me/Uucky的小站_files/jquery.swatchbook.js
@@ -0,0 +1,249 @@
1/**
2 * jquery.swatchbook.js v1.1.0
3 * http://www.codrops.com
4 *
5 * Licensed under the MIT license.
6 * http://www.opensource.org/licenses/mit-license.php
7 *
8 * Copyright 2012, Codrops
9 * http://www.codrops.com
10 */
11
12;( function( $, window, undefined ) {
13
14 'use strict';
15
16 // global
17 var Modernizr = window.Modernizr;
18
19 jQuery.fn.reverse = [].reverse;
20
21 $.SwatchBook = function( options, element ) {
22
23 this.$el = $( element );
24 this._init( options );
25
26 };
27
28 $.SwatchBook.defaults = {
29 // index of initial centered item
30 center : 6,
31 // number of degrees that is between each item
32 angleInc : 8,
33 speed : 700,
34 easing : 'ease',
35 // amount in degrees for the opened item's next sibling
36 proximity : 45,
37 // amount in degrees between the opened item's next siblings
38 neighbor : 4,
39 // animate on load
40 onLoadAnim : true,
41 // if it should be closed by default
42 initclosed : false,
43 // index of the element that when clicked, triggers the open/close function
44 // by default there is no such element
45 closeIdx : -1,
46 // open one specific item initially (overrides initclosed)
47 openAt : -1
48 };
49
50 $.SwatchBook.prototype = {
51
52 _init : function( options ) {
53
54 this.options = $.extend( true, {}, $.SwatchBook.defaults, options );
55
56 this.$items = this.$el.children( 'div' );
57 this.itemsCount = this.$items.length;
58 this.current = -1;
59 this.support = Modernizr.csstransitions;
60 this.cache = [];
61
62 if( this.options.onLoadAnim ) {
63 this._setTransition();
64 }
65
66 if( !this.options.initclosed ) {
67 this._center( this.options.center, this.options.onLoadAnim );
68 }
69 else {
70
71 this.isClosed = true;
72 if( !this.options.onLoadAnim ) {
73 this._setTransition();
74 }
75
76 }
77
78 if( this.options.openAt >= 0 && this.options.openAt < this.itemsCount ) {
79 this._openItem( this.$items.eq( this.options.openAt ) );
80 }
81
82 this._initEvents();
83
84 },
85 _setTransition : function() {
86
87 if( this.support ) {
88 this.$items.css( { 'transition': 'all ' + this.options.speed + 'ms ' + this.options.easing } );
89 }
90
91 },
92 _openclose : function() {
93
94 this.isClosed ? this._center( this.options.center, true ) : this.$items.css( { 'transform' : 'rotate(0deg)' } );
95 this.isClosed = !this.isClosed;
96
97 },
98 _center : function( idx, anim ) {
99
100 var self = this;
101
102 this.$items.each( function( i ) {
103
104 var transformStr = 'rotate(' + ( self.options.angleInc * ( i - idx ) ) + 'deg)';
105 $( this ).css( { 'transform' : transformStr } );
106
107 } );
108
109 },
110 _openItem : function( $item ) {
111
112 var itmIdx = $item.index();
113
114 if( itmIdx !== this.current ) {
115
116 if( this.options.closeIdx !== -1 && itmIdx === this.options.closeIdx ) {
117
118 this._openclose();
119 this._setCurrent();
120
121 }
122 else {
123
124 this._setCurrent( $item );
125 $item.css( { 'transform' : 'rotate(0deg)' } );
126 this._rotateSiblings( $item );
127
128 }
129
130 }
131
132 },
133 _initEvents : function() {
134
135 var self = this;
136
137 this.$items.on( 'click.swatchbook', function( event ) {
138 self._openItem( $( this ) );
139 } );
140
141 },
142 _rotateSiblings : function( $item ) {
143
144 var self = this,
145 idx = $item.index(),
146 $cached = this.cache[ idx ],
147 $siblings;
148
149 if( $cached ) {
150 $siblings = $cached;
151 }
152 else {
153
154 $siblings = $item.siblings();
155 this.cache[ idx ] = $siblings;
156
157 }
158
159 $siblings.each( function( i ) {
160
161 var rotateVal = i < idx ?
162 self.options.angleInc * ( i - idx ) :
163 i - idx === 1 ?
164 self.options.proximity :
165 self.options.proximity + ( i - idx - 1 ) * self.options.neighbor;
166
167 var transformStr = 'rotate(' + rotateVal + 'deg)';
168
169 $( this ).css( { 'transform' : transformStr } );
170
171 } );
172
173 },
174 _setCurrent : function( $el ) {
175
176 this.current = $el ? $el.index() : -1;
177 this.$items.removeClass( 'ff-active' );
178 if( $el ) {
179 $el.addClass( 'ff-active' );
180 }
181
182 }
183
184 };
185
186 var logError = function( message ) {
187
188 if ( window.console ) {
189
190 window.console.error( message );
191
192 }
193
194 };
195
196 $.fn.swatchbook = function( options ) {
197
198 var instance = $.data( this, 'swatchbook' );
199
200 if ( typeof options === 'string' ) {
201
202 var args = Array.prototype.slice.call( arguments, 1 );
203
204 this.each(function() {
205
206 if ( !instance ) {
207
208 logError( "cannot call methods on swatchbook prior to initialization; " +
209 "attempted to call method '" + options + "'" );
210 return;
211
212 }
213
214 if ( !$.isFunction( instance[options] ) || options.charAt(0) === "_" ) {
215
216 logError( "no such method '" + options + "' for swatchbook instance" );
217 return;
218
219 }
220
221 instance[ options ].apply( instance, args );
222
223 });
224
225 }
226 else {
227
228 this.each(function() {
229
230 if ( instance ) {
231
232 instance._init();
233
234 }
235 else {
236
237 instance = $.data( this, 'swatchbook', new $.SwatchBook( options, this ) );
238
239 }
240
241 });
242
243 }
244
245 return instance;
246
247 };
248
249} )( jQuery, window ); \ No newline at end of file
Powered by cgit v1.2.3 (git 2.41.0)