今天要为大家带来一款由jquery实现的整屏切换特效,在右侧有圆型小标,每点一个切换一屏。当然,你也可以滚动鼠标来切换页面。效果非常好。我们看下效果吧
html代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
< div class = "wrapper active-page4" > < div class = "page page1" > < h2 > First page</ h2 > </ div > < div class = "page page2" > < h2 > Second page</ h2 > </ div > < div class = "page page3" > < h2 > Third page</ h2 > </ div > < div class = "page page4" > < h2 > Fourth page</ h2 > </ div > </ div > < div class = "nav-panel" > < div class = "scroll-btn up" > </ div > < div class = "scroll-btn down" > </ div > < nav > < ul > < li data-target = "1" class = "nav-btn nav-page1" ></ li > < li data-target = "2" class = "nav-btn nav-page2" ></ li > < li data-target = "3" class = "nav-btn nav-page3" ></ li > < li data-target = "4" class = "nav-btn nav-page4 active" ></ li > </ ul > </ nav > </ div > |
css代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
*, *:before, *:after { -moz-box-sizing: border-box; box-sizing: border-box; margin : 0 ; padding : 0 ; } .inner, .nav-panel ul .nav-btn:after { content : "" ; position : absolute ; top : 50% ; left : 50% ; } html, body { width : 100% ; height : 100% ; overflow : hidden ; } @media ( max-width : 767px ) { body { font-size : 70% ; } } .wrapper { position : absolute ; top : 0 ; left : 0 ; width : 100% ; height : 100% ; -webkit-transition: -webkit-transform 1.5 s; transition: transform 1.5 s; -webkit-perspective: 3000 ; perspective: 3000 ; -webkit-transform-style: preserve -3 d; transform-style: preserve -3 d; } .wrapper .page { position : relative ; width : 100% ; height : 100% ; -webkit-transform: rotateX( 180 deg) scale( 0.3 ); transform: rotateX( 180 deg) scale( 0.3 ); -webkit-backface- visibility : hidden ; backface- visibility : hidden ; -webkit-transition: -webkit-transform 1 s ease-in-out; transition: transform 1 s ease-in-out; will-change: transform; } .wrapper .page h 2 { color : #fff ; position : absolute ; top : 50% ; left : 50% ; -webkit-transform: translateX( -50% ) translateY( -50% ); -ms-transform: translateX( -50% ) translateY( -50% ); transform: translateX( -50% ) translateY( -50% ); text-transform : uppercase ; font-size : 3em ; } .wrapper .page.page 1 { background-color : #66a6b8 ; background-image : -webkit-gradient(linear, left top , left bottom , color-stop( 20% , #66a6b8 ), color-stop( 80% , #5471B9 )); background-image : -webkit-linear-gradient( -280 deg, #66a6b8 20% , #5471B9 80% ); background-image : -webkit-linear-gradient( 80 deg, #66a6b8 20% , #5471B9 80% ); background-image : linear-gradient( 10 deg, #66a6b8 20% , #5471B9 80% ); } .wrapper .page.page 2 { background-color : #f29c54 ; background-image : -webkit-gradient(linear, left top , left bottom , color-stop( 0% , #f29c54 ), color-stop( 100% , #DB4367 )); background-image : -webkit-linear-gradient( -315 deg, #f29c54 0% , #DB4367 100% ); background-image : -webkit-linear-gradient( 45 deg, #f29c54 0% , #DB4367 100% ); background-image : linear-gradient( 45 deg, #f29c54 0% , #DB4367 100% ); } .wrapper .page.page 3 { background-color : #23af56 ; background-image : -webkit-gradient(linear, left top , left bottom , color-stop( 0% , #23af56 ), color-stop( 100% , #67A79A )); background-image : -webkit-linear-gradient( -405 deg, #23af56 0% , #67A79A 100% ); background-image : -webkit-linear-gradient( 315 deg, #23af56 0% , #67A79A 100% ); background-image : linear-gradient( 135 deg, #23af56 0% , #67A79A 100% ); } .wrapper .page.page 4 { background-color : #412F2F ; background-image : -webkit-gradient(linear, left top , left bottom , color-stop( 15% , #412F2F ), color-stop( 85% , #6B2686 )); background-image : -webkit-linear-gradient( -430 deg, #412F2F 15% , #6B2686 85% ); background-image : -webkit-linear-gradient( 290 deg, #412F2F 15% , #6B2686 85% ); background-image : linear-gradient( 160 deg, #412F2F 15% , #6B2686 85% ); } .wrapper.active-page 1 { -webkit-transform: translateY( 0% ); -ms-transform: translateY( 0% ); transform: translateY( 0% ); } .wrapper.active-page 1 .page.page 1 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .wrapper.active-page 2 { -webkit-transform: translateY( -100% ); -ms-transform: translateY( -100% ); transform: translateY( -100% ); } .wrapper.active-page 2 .page.page 2 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .wrapper.active-page 3 { -webkit-transform: translateY( -200% ); -ms-transform: translateY( -200% ); transform: translateY( -200% ); } .wrapper.active-page 3 .page.page 3 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .wrapper.active-page 4 { -webkit-transform: translateY( -300% ); -ms-transform: translateY( -300% ); transform: translateY( -300% ); } .wrapper.active-page 4 .page.page 4 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .wrapper.active-page 5 { -webkit-transform: translateY( -400% ); -ms-transform: translateY( -400% ); transform: translateY( -400% ); } .wrapper.active-page 5 .page.page 5 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .wrapper.active-page 6 { -webkit-transform: translateY( -500% ); -ms-transform: translateY( -500% ); transform: translateY( -500% ); } .wrapper.active-page 6 .page.page 6 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .wrapper.active-page 7 { -webkit-transform: translateY( -600% ); -ms-transform: translateY( -600% ); transform: translateY( -600% ); } .wrapper.active-page 7 .page.page 7 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .wrapper.active-page 8 { -webkit-transform: translateY( -700% ); -ms-transform: translateY( -700% ); transform: translateY( -700% ); } .wrapper.active-page 8 .page.page 8 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .wrapper.active-page 9 { -webkit-transform: translateY( -800% ); -ms-transform: translateY( -800% ); transform: translateY( -800% ); } .wrapper.active-page 9 .page.page 9 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .wrapper.active-page 10 { -webkit-transform: translateY( -900% ); -ms-transform: translateY( -900% ); transform: translateY( -900% ); } .wrapper.active-page 10 .page.page 10 { -webkit-transform: scale( 1 ); -ms-transform: scale( 1 ); transform: scale( 1 ); } .nav-panel { position : fixed ; top : 50% ; right : 1em ; -webkit-transform: translateY( -50% ); -ms-transform: translateY( -50% ); transform: translateY( -50% ); z-index : 1000 ; -webkit-transition: opacity 0.5 s, -webkit-transform 0.5 s cubic-bezier( 0.57 , 1.2 , 0.68 , 2.6 ); transition: opacity 0.5 s, transform 0.5 s cubic-bezier( 0.57 , 1.2 , 0.68 , 2.6 ); will-change: transform, opacity; } .nav-panel.invisible { opacity: 0 ; -webkit-transform: translateY( -50% ) scale( 0.5 ); -ms-transform: translateY( -50% ) scale( 0.5 ); transform: translateY( -50% ) scale( 0.5 ); } .nav-panel ul { list-style-type : none ; } .nav-panel ul .nav-btn { position : relative ; overflow : hidden ; width : 1em ; height : 1em ; margin-bottom : 0.5em ; border : 0.12em solid #fff ; border-radius: 50% ; cursor : pointer ; -webkit-transition: border-color, -webkit-transform 0.3 s; transition: border-color, transform 0.3 s; will-change: border-color, transform; } .nav-panel ul .nav-btn:after { width : 100% ; height : 100% ; border-radius: 50% ; -webkit-transform: translateX( -50% ) translateY( -50% ) scale( 0.3 ); -ms-transform: translateX( -50% ) translateY( -50% ) scale( 0.3 ); transform: translateX( -50% ) translateY( -50% ) scale( 0.3 ); background-color : #fff ; opacity: 0 ; -webkit-transition: -webkit-transform, opacity 0.3 s; transition: transform, opacity 0.3 s; will-change: transform, opacity; } .nav-panel ul .nav-btn.active:after, .nav-panel ul .nav-btn:hover:after { -webkit-transform: translateX( -50% ) translateY( -50% ) scale( 0.7 ); -ms-transform: translateX( -50% ) translateY( -50% ) scale( 0.7 ); transform: translateX( -50% ) translateY( -50% ) scale( 0.7 ); opacity: 1 ; } .nav-panel ul .nav-btn:hover { border-color : yellow; -webkit-transform: scale( 1.2 ); -ms-transform: scale( 1.2 ); transform: scale( 1.2 ); } .nav-panel ul .nav-btn:hover:after { background-color : yellow; } .nav-panel .scroll-btn { position : absolute ; left : 0 ; width : 1em ; height : 1em ; border : 0.2em solid #fff ; border-left : none ; border-bottom : none ; cursor : pointer ; -webkit-transform-origin: 50% 50% ; -ms-transform-origin: 50% 50% ; transform-origin: 50% 50% ; -webkit-transition: border-color 0.3 s; transition: border-color 0.3 s; } .nav-panel .scroll-btn.up { top : -1.6em ; -webkit-transform: rotate( -45 deg); -ms-transform: rotate( -45 deg); transform: rotate( -45 deg); } .nav-panel .scroll-btn.down { bottom : -1.2em ; -webkit-transform: rotate( 135 deg); -ms-transform: rotate( 135 deg); transform: rotate( 135 deg); } .nav-panel .scroll-btn:hover { border-color : yellow; } |
js代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
'use strict' ; $(document).ready( function () { var $wrap = $( ".wrapper" ), pages = $( ".page" ).length, scrolling = false , currentPage = 1, $navPanel = $( ".nav-panel" ), $scrollBtn = $( ".scroll-btn" ), $navBtn = $( ".nav-btn" ); /***************************** ***** NAVIGATE FUNCTIONS ***** *****************************/ function manageClasses() { $wrap.removeClass( function (index, css) { return (css.match(/(^|\s)active-page\S+/g) || []).join( ' ' ); }); $wrap.addClass( "active-page" + currentPage); $navBtn.removeClass( "active" ); $( ".nav-btn.nav-page" + currentPage).addClass( "active" ); $navPanel.addClass( "invisible" ); scrolling = true ; setTimeout( function () { $navPanel.removeClass( "invisible" ); scrolling = false ; }, 1000); } function navigateUp() { if (currentPage > 1) { currentPage--; if (Modernizr.csstransforms) { manageClasses(); } else { $wrap.animate({ "top" : "-" + ((currentPage - 1) * 100) + "%" }, 1000); } } } function navigateDown() { if (currentPage < pages) { currentPage++; if (Modernizr.csstransforms) { manageClasses(); } else { $wrap.animate({ "top" : "-" + ((currentPage - 1) * 100) + "%" }, 1000); } } } /********************* ***** MOUSEWHEEL ***** *********************/ $(document).on( "mousewheel DOMMouseScroll" , function (e) { if (!scrolling) { if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) { navigateUp(); } else { navigateDown(); } } }); /************************** ***** RIGHT NAVIGATION **** **************************/ /* NAV UP/DOWN BTN PAGE NAVIGATION */ $(document).on( "click" , ".scroll-btn" , function () { if ($( this ).hasClass( "up" )) { navigateUp(); } else { navigateDown(); } }); /* NAV CIRCLE DIRECT PAGE BTN */ $(document).on( "click" , ".nav-btn" , function () { if (!scrolling) { var target = $( this ).attr( "data-target" ); if (Modernizr.csstransforms) { $wrap.removeClass( function (index, css) { return (css.match(/(^|\s)active-page\S+/g) || []).join( ' ' ); }); $wrap.addClass( "active-page" + target); $navBtn.removeClass( "active" ); $( this ).addClass( "active" ); $navPanel.addClass( "invisible" ); currentPage = target; scrolling = true ; setTimeout( function () { $navPanel.removeClass( "invisible" ); scrolling = false ; }, 1000); } else { $wrap.animate({ "top" : "-" + ((target - 1) * 100) + "%" }, 1000); } } }); }); //@ sourceURL=pen.js |