1
1
$ ( function ( ) {
2
2
3
-
4
-
5
3
var title = $ ( "h1" ) . text ( ) ;
4
+ var title_height = $ ( "h1" ) . height ( ) ;
5
+
6
6
$ ( "h1 span" ) . each ( function ( idx , element ) {
7
7
var x = 20 ;
8
8
var z = title . length / 2 * x - Math . abs ( ( title . length / 2 - idx ) * x ) ;
@@ -11,16 +11,22 @@ $(function() {
11
11
//perspective: 70,
12
12
delay : 1000 + idx * 100 ,
13
13
duration : 1000 ,
14
- easing : 'cos ' ,
14
+ easing : 'ease ' ,
15
15
callback : function ( ) {
16
16
if ( idx == title . length - 1 ) {
17
17
$ ( "h1" ) . snabbt ( {
18
+ offset : [ 0 , - title_height , 0 ] ,
19
+ from_position : [ 0 , title_height , 0 ] ,
20
+ position : [ 0 , title_height , 0 ] ,
18
21
rotation : [ - Math . PI / 4 , 0 , 0 ] ,
19
22
perspective : 100 ,
20
- easing : 'sqrt ' ,
23
+ easing : 'linear ' ,
21
24
delay : 400 ,
22
25
duration : 1000
23
26
} ) . then ( {
27
+ offset : [ 0 , - title_height , 0 ] ,
28
+ from_position : [ 0 , title_height , 0 ] ,
29
+ position : [ 0 , title_height , 0 ] ,
24
30
easing : 'spring' ,
25
31
perspective : 100 ,
26
32
spring_constant : 0.1 ,
@@ -38,27 +44,27 @@ $(function() {
38
44
var w = $ ( "h1" ) . width ( ) ;
39
45
$ ( "h1" ) . snabbt ( {
40
46
skew : [ 0 , 0.9 ] ,
41
- easing : 'cos ' ,
47
+ easing : 'ease ' ,
42
48
} ) . then ( {
43
49
position : [ 2 * w , 0 , 0 ] ,
44
50
skew : [ 0 , 0 ] ,
45
- easing : 'sqrt ' ,
51
+ easing : 'ease-in ' ,
46
52
duration : 200 ,
47
53
} ) . then ( {
48
54
offset : [ w / 2 , 0 , 0 ] ,
49
55
rotation : [ 0 , Math . PI , 0 ] ,
50
56
from_position : [ 2 * w - w / 2 , 0 , 0 ] ,
51
57
position : [ 2 * w - w / 2 , 0 , 0 ] ,
52
58
perspective : 500 ,
53
- easing : 'cos ' ,
59
+ easing : 'ease ' ,
54
60
delay : 200 ,
55
61
} ) . then ( {
56
62
offset : [ - w / 2 , 0 , 0 ] ,
57
63
from_rotation : [ 0 , - Math . PI , 0 ] ,
58
64
from_position : [ w - w / 2 , 0 , 0 ] ,
59
65
position : [ w - w / 2 , 0 , 0 ] ,
60
66
perspective : 500 ,
61
- easing : 'cos ' ,
67
+ easing : 'ease ' ,
62
68
} ) ;
63
69
} ) ;
64
70
@@ -69,15 +75,15 @@ $(function() {
69
75
rotation : [ 0 , 0 , Math . PI ] ,
70
76
duration : 1000 ,
71
77
delay : 100 ,
72
- easing : 'cos '
78
+ easing : 'ease '
73
79
} ) ;
74
80
} ;
75
81
76
82
// Chaining example
77
83
document . getElementById ( 'chaining-example-execute' ) . onclick = function ( ) {
78
84
snabbt ( document . getElementById ( 'chaining-example-execute' ) , {
79
85
position : [ 100 , 0 , 0 ] ,
80
- easing : 'cos '
86
+ easing : 'ease '
81
87
} ) . then ( {
82
88
from_rotation : [ 0 , 0 , - 2 * Math . PI ] ,
83
89
easing : 'spring' ,
@@ -87,13 +93,56 @@ $(function() {
87
93
} ;
88
94
89
95
96
+ // Easings
97
+ var easing_demos = document . querySelectorAll ( '.easing-demo' ) ;
98
+ for ( var i = 0 ; i < easing_demos . length ; ++ i ) {
99
+ var container = easing_demos [ i ] ;
100
+ var easing_name = container . attributes [ 'data-easing-name' ] ;
101
+ var element = container . children [ 0 ] ;
102
+ container . onclick = function ( container , element , easing_name ) {
103
+ var container_width = container . offsetWidth ;
104
+ var element_width = element . offsetWidth ;
105
+ snabbt ( element , 'stop' ) ;
106
+ snabbt ( element , {
107
+ position : [ container_width - element_width , 0 , 0 ] ,
108
+ easing : easing_name . value ,
109
+ duration : 500
110
+ } ) ;
111
+ } . bind ( undefined , container , element , easing_name ) ;
112
+ }
113
+
114
+ // Spring easings
115
+ $ ( "#spring-example" ) . on ( 'click' , function ( ) {
116
+ $ ( "#spring-example" ) . snabbt ( {
117
+ position : [ 100 , 0 , 0 ] ,
118
+ rotation : [ 0 , 0 , 2 * Math . PI ] ,
119
+ easing : 'spring' ,
120
+ spring_constant : 0.3 ,
121
+ spring_deacceleration : 0.8 ,
122
+ } ) . then ( {
123
+ from_rotation : [ 0 , 0 , 0 ] ,
124
+ easing : 'spring' ,
125
+ spring_constant : 0.3 ,
126
+ spring_deacceleration : 0.8 ,
127
+ } ) ;
128
+ } ) ;
129
+
130
+ // Custom easing
131
+ $ ( "#custom-easer" ) . on ( 'click' , function ( ) {
132
+ $ ( "#custom-easer" ) . snabbt ( {
133
+ position : [ 200 , 0 , 0 ] ,
134
+ easing : function ( value ) {
135
+ return Math . sin ( Math . PI * value ) ;
136
+ }
137
+ } ) ;
138
+ } ) ;
139
+
90
140
// Value feed example
91
141
$ ( "#value-feed-example" ) . on ( 'click' , function ( ) {
92
142
$ ( "#value-feed-example" ) . snabbt ( {
93
143
value_feeder : function ( i ) {
94
- var y = 50 * Math . sin ( i * 4 * Math . PI ) ;
95
144
var x = Math . sin ( i * Math . PI ) ;
96
- return snabbtjs . mult ( snabbtjs . scale ( 1 + x , 1 + x ) , snabbtjs . trans ( x * 400 , y , 0 ) ) ;
145
+ return snabbtjs . mult ( snabbtjs . rotZ ( Math . sin ( 6 * i * Math . PI ) ) , snabbtjs . trans ( x * 200 , 0 , 0 ) ) ;
97
146
} ,
98
147
duration : 1000 ,
99
148
} ) ;
0 commit comments