File tree Expand file tree Collapse file tree 5 files changed +58
-4
lines changed
Expand file tree Collapse file tree 5 files changed +58
-4
lines changed Original file line number Diff line number Diff line change 116116 swiper.next();
117117```
118118
119+ - ` go ` : 主动滑动到指定界面。
120+
121+ ```
122+ var swiper = new Swiper();
123+ swiper.go(1);
124+ ```
119125##License
120126
121127swiper is available under the terms of the [ MIT License] ( http://www.opensource.org/licenses/mit-license.php ) .
Original file line number Diff line number Diff line change 88 height : 100% ;
99 overflow : hidden;
1010 -webkit-transition : all 0.3s ease;
11- transition : all 0.3s ease;
11+ transition : all 0.3s ease;
1212}
1313.item {
1414 height : 100% ;
Original file line number Diff line number Diff line change 2828 this . _prev = 0 ;
2929 this . _current = 0 ;
3030 this . _offset = 0 ;
31+ this . _goto = - 1 ;
3132 this . _eventHandlers = { } ;
3233
3334 this . $container = document . querySelector ( this . _options . container ) ;
134135 return false ;
135136 }
136137
137- if ( me . _current != me . _prev ) {
138+ if ( me . _current != me . _prev || me . _goto > - 1 ) {
138139 me . _activate ( me . _current ) ;
139140 var cb = me . _eventHandlers . swiped || noop ;
140141 cb . apply ( me , [ me . _prev , me . _current ] ) ;
142+ me . _goto = - 1 ;
141143 }
142144 e . preventDefault ( ) ;
143145 } , false ) ;
180182 } ) ;
181183 } ;
182184
185+ /**
186+ * goto x page
187+ */
188+ Swiper . prototype . go = function ( index ) {
189+ if ( index < 0 || index > this . count - 1 || index === this . _current ) {
190+ return ;
191+ }
192+
193+ if ( index === 0 ) {
194+ this . _current = 0 ;
195+ this . _prev = 0 ;
196+ } else {
197+ this . _current = index ;
198+ this . _prev = index - 1 ;
199+ }
200+
201+ this . _goto = index ;
202+ this . _show ( this . _current ) ;
203+
204+ return this ;
205+ } ;
206+
183207 /**
184208 * show next page
185209 */
Original file line number Diff line number Diff line change 2222 this . _prev = 0 ;
2323 this . _current = 0 ;
2424 this . _offset = 0 ;
25+ this . _goto = - 1 ;
2526 this . _eventHandlers = { } ;
2627
2728 this . $container = document . querySelector ( this . _options . container ) ;
128129 return false ;
129130 }
130131
131- if ( me . _current != me . _prev ) {
132+ if ( me . _current != me . _prev || me . _goto > - 1 ) {
132133 me . _activate ( me . _current ) ;
133134 var cb = me . _eventHandlers . swiped || noop ;
134135 cb . apply ( me , [ me . _prev , me . _current ] ) ;
136+ me . _goto = - 1 ;
135137 }
136138 e . preventDefault ( ) ;
137139 } , false ) ;
174176 } ) ;
175177 } ;
176178
179+ /**
180+ * goto x page
181+ */
182+ Swiper . prototype . go = function ( index ) {
183+ if ( index < 0 || index > this . count - 1 || index === this . _current ) {
184+ return ;
185+ }
186+
187+ if ( index === 0 ) {
188+ this . _current = 0 ;
189+ this . _prev = 0 ;
190+ } else {
191+ this . _current = index ;
192+ this . _prev = index - 1 ;
193+ }
194+
195+ this . _goto = index ;
196+ this . _show ( this . _current ) ;
197+
198+ return this ;
199+ } ;
200+
177201 /**
178202 * show next page
179203 */
You can’t perform that action at this time.
0 commit comments