├── .gitignore ├── images ├── github.png ├── tabzilla-static.png ├── tabzilla-static-high-res.png └── burger.svg ├── tabzilla.css ├── README.md ├── index.html ├── main.js ├── demos ├── lib │ ├── prism.css │ ├── prism.js │ └── Tween.js ├── js-animations-vs-web-animations.html ├── css-vs-animations-code.html ├── accessibility.html └── style-guide.html ├── gallery.html ├── styles.css └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .jshintrc 3 | -------------------------------------------------------------------------------- /images/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozdevs/Animation-examples/HEAD/images/github.png -------------------------------------------------------------------------------- /images/tabzilla-static.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozdevs/Animation-examples/HEAD/images/tabzilla-static.png -------------------------------------------------------------------------------- /images/tabzilla-static-high-res.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mozdevs/Animation-examples/HEAD/images/tabzilla-static-high-res.png -------------------------------------------------------------------------------- /images/burger.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tabzilla.css: -------------------------------------------------------------------------------- 1 | #tabzilla { 2 | float: right; 3 | position: relative; 4 | } 5 | 6 | #tabzilla a { 7 | text-indent: 120%; 8 | white-space: nowrap; 9 | overflow: hidden; 10 | background-image: url('images/tabzilla-static.png'); 11 | background-repeat: no-repeat; 12 | display: block; 13 | height: 37px; 14 | position: relative; 15 | width: 147px; 16 | z-index: 2; 17 | box-shadow: none; 18 | } 19 | 20 | @media (-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx) { 21 | #tabzilla a { 22 | background-image: url('images/tabzilla-static-high-res.png'); 23 | background-size: 147px 37px; 24 | } 25 | } 26 | 27 | #tabzilla:before { 28 | background-color: transparent; 29 | content: ''; 30 | display: block; 31 | height: 26px; 32 | left: 28px; 33 | position: absolute; 34 | top: 0; 35 | width: 88px; 36 | z-index: 1; 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Web Animations API Examples 2 | 3 | This is a collection of [Web Animations](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) demos. This API allows creation and control of animations through JavaScript. 4 | 5 | - [View demos online](https://mozdevs.github.io/Animation-examples/) 6 | - or [download](https://github.com/mozdevs/Animation-examples/archive/gh-pages.zip) this repository and open `index.html` to browse examples locally. 7 | 8 | ## Requirements 9 | 10 | For the demos to work, you need a browser that supports the Web Animations API. In Firefox, it is available from **version 48**. For other browsers, check out this [support table](http://caniuse.com/#feat=web-animation). 11 | 12 | ## Contribute 13 | 14 | If you would like to submit additional demos featuring more use cases, please create a pull request. 15 | 16 | For bugs and general discussion, use the [issue tracker](https://github.com/mozdevs/Animation-examples/issues). 17 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Web Animations examples 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 17 | 20 | 34 |
35 | 36 |
37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | 4 | // TODO: we need to display local content instead of the one at Github 5 | const GITHUB_RAW = 'https://raw.githubusercontent.com/mozdevs/Animation-examples/'; 6 | function buildRawCodeURL(base) { 7 | let path = base.replace(window.location.href, ''); 8 | return `${GITHUB_RAW}gh-pages/${path}`; 9 | } 10 | 11 | window.onload = function () { 12 | let menu = document.querySelector('.sidebar'); 13 | let burger = document.querySelector('.burger'); 14 | let viewer = document.querySelector('.viewer-wrapper'); 15 | let links = Array.from(document.querySelectorAll('a[target=viewer]')); 16 | let viewSourceLink = document.querySelector('.view-source a'); 17 | let viewSource = document.querySelector('.view-source'); 18 | 19 | 20 | // ------------------------------------------------------------------------- 21 | // handle View Source Code button 22 | // ------------------------------------------------------------------------- 23 | 24 | links.forEach(function (link) { 25 | link.addEventListener('click', function(event) { 26 | // only update and show the button for demos 27 | if (/demos\//.test(link.href)) { 28 | viewSourceLink.href = buildRawCodeURL(link.href); 29 | viewSource.style.display = 'block'; 30 | } 31 | else { 32 | viewSourceLink.href = '#'; 33 | viewSource.style.display = 'none'; 34 | } 35 | }); 36 | }); 37 | 38 | // ------------------------------------------------------------------------- 39 | // handle responsive menu 40 | // ------------------------------------------------------------------------- 41 | 42 | let hideMenu = function () { 43 | viewer.classList.add('mobile-show'); 44 | viewer.classList.remove('mobile-hidden'); 45 | 46 | menu.classList.add('mobile-hidden'); 47 | menu.classList.remove('mobile-show'); 48 | }; 49 | 50 | let showMenu = function () { 51 | viewer.classList.add('mobile-hidden'); 52 | viewer.classList.remove('mobile-show'); 53 | 54 | menu.classList.add('mobile-show'); 55 | menu.classList.remove('mobile-hidden'); 56 | 57 | viewSourceLink.href = '#'; 58 | viewSource.style.display = 'none'; 59 | }; 60 | 61 | links.forEach(function(link) { 62 | link.addEventListener('click', hideMenu); 63 | }); 64 | 65 | burger.querySelector('button').addEventListener('click', showMenu); 66 | }; 67 | -------------------------------------------------------------------------------- /demos/lib/prism.css: -------------------------------------------------------------------------------- 1 | /* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript */ 2 | /** 3 | * prism.js default theme for JavaScript, CSS and HTML 4 | * Based on dabblet (http://dabblet.com) 5 | * @author Lea Verou 6 | */ 7 | 8 | code[class*="language-"], 9 | pre[class*="language-"] { 10 | color: black; 11 | background: none; 12 | text-shadow: 0 1px white; 13 | font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; 14 | text-align: left; 15 | white-space: pre; 16 | word-spacing: normal; 17 | word-break: normal; 18 | word-wrap: normal; 19 | line-height: 1.5; 20 | 21 | -moz-tab-size: 4; 22 | -o-tab-size: 4; 23 | tab-size: 4; 24 | 25 | -webkit-hyphens: none; 26 | -moz-hyphens: none; 27 | -ms-hyphens: none; 28 | hyphens: none; 29 | } 30 | 31 | pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection, 32 | code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection { 33 | text-shadow: none; 34 | background: #b3d4fc; 35 | } 36 | 37 | pre[class*="language-"]::selection, pre[class*="language-"] ::selection, 38 | code[class*="language-"]::selection, code[class*="language-"] ::selection { 39 | text-shadow: none; 40 | background: #b3d4fc; 41 | } 42 | 43 | @media print { 44 | code[class*="language-"], 45 | pre[class*="language-"] { 46 | text-shadow: none; 47 | } 48 | } 49 | 50 | /* Code blocks */ 51 | pre[class*="language-"] { 52 | padding: 1em; 53 | margin: .5em 0; 54 | overflow: auto; 55 | } 56 | 57 | :not(pre) > code[class*="language-"], 58 | pre[class*="language-"] { 59 | background: #f5f2f0; 60 | } 61 | 62 | /* Inline code */ 63 | :not(pre) > code[class*="language-"] { 64 | padding: .1em; 65 | border-radius: .3em; 66 | white-space: normal; 67 | } 68 | 69 | .token.comment, 70 | .token.prolog, 71 | .token.doctype, 72 | .token.cdata { 73 | color: slategray; 74 | } 75 | 76 | .token.punctuation { 77 | color: #999; 78 | } 79 | 80 | .namespace { 81 | opacity: .7; 82 | } 83 | 84 | .token.property, 85 | .token.tag, 86 | .token.boolean, 87 | .token.number, 88 | .token.constant, 89 | .token.symbol, 90 | .token.deleted { 91 | color: #905; 92 | } 93 | 94 | .token.selector, 95 | .token.attr-name, 96 | .token.string, 97 | .token.char, 98 | .token.builtin, 99 | .token.inserted { 100 | color: #690; 101 | } 102 | 103 | .token.operator, 104 | .token.entity, 105 | .token.url, 106 | .language-css .token.string, 107 | .style .token.string { 108 | color: #a67f59; 109 | background: hsla(0, 0%, 100%, .5); 110 | } 111 | 112 | .token.atrule, 113 | .token.attr-value, 114 | .token.keyword { 115 | color: #07a; 116 | } 117 | 118 | .token.function { 119 | color: #DD4A68; 120 | } 121 | 122 | .token.regex, 123 | .token.important, 124 | .token.variable { 125 | color: #e90; 126 | } 127 | 128 | .token.important, 129 | .token.bold { 130 | font-weight: bold; 131 | } 132 | .token.italic { 133 | font-style: italic; 134 | } 135 | 136 | .token.entity { 137 | cursor: help; 138 | } 139 | 140 | -------------------------------------------------------------------------------- /gallery.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Web Animations examples 5 | 6 | 7 | 8 | 9 | 10 |
11 |

Web animations examples

12 |

Here's a collection of examples using the 13 | Web Animations API. This API allows you to create high-performance animations, and also inspect and manipulate them, as well as those created by CSS that are currently running. 14 |

15 | 19 | 20 |

Index

21 | 31 |

Resources

32 | 38 |
39 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /demos/js-animations-vs-web-animations.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JS Animations vs Web Animations 5 | 6 | 7 | 8 | 9 | 10 |

vs

11 |
12 |
13 |
14 |
15 | 133 | 196 | 197 | 198 | -------------------------------------------------------------------------------- /demos/css-vs-animations-code.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Web Animations Example - CSS vs Web Animations code comparison 4 | 5 | 6 | 7 | 8 | 45 | 46 | 47 |
48 |

Comparing CSS and Web Animations

49 |

This is a comparison between CSS code and JavaScript code that use the Web Animations API to achieve the same effects. If you are already familiar with defining CSS animations, you will feel right at home with the Web Animations API.

50 |
51 |

Looped color animation

52 |
53 |

CSS

54 |
55 | 56 |
57 |
58 |
.rainbow {
 59 |     animation: rainbow 2s alternate infinite;
 60 | }
 61 | 
 62 | @keyframes rainbow {
 63 |     0% { background: #ff004d; }
 64 |     20% { background: #ff77ab; }
 65 |     50% { background: #00e756; }
 66 |     80% { background: #29adff; }
 67 |     100% { background: #ff77ab;}
 68 | }
 69 | 
70 |
71 |
72 |
73 |

Web Animations API

74 |
75 | 76 |
77 |
78 |
let el = document.querySelector('.rainbow');
 79 | el.animate([
 80 |     { background: '#ff004d', offset: 0 },
 81 |     { background: '#ff77ab', offset: 0.20 },
 82 |     { background: '#00e756', offset: 0.5 },
 83 |     { background: '#29adff', offset: 0.80 },
 84 |     { background: '#ff77ab', offset: 1 }
 85 | ], {
 86 |     duration: 2000,
 87 |     direction: 'alternate',
 88 |     iterations: Infinity
 89 | });
 90 | 
91 |
92 |
93 |
94 | 95 |
96 |

Linear transform with user events

97 |
98 |

CSS

99 |
100 |

101 | 102 | Mouse over the button 103 |

104 |
105 |
106 |
button {
107 |     transform: scale(1);
108 |     transition: all 0.5s;
109 | }
110 | 
111 | button:hover {
112 |     transform: scale(1.25);
113 | }
114 | 
115 |
116 |
117 |

Web Animations API

118 |
119 |

120 | 121 | Mouse over the button 122 |

123 |
124 |
125 |
let el = document.querySelector('.animated');
126 | el.addEventListener('mouseover', function () {
127 |     let anim = el.animate({
128 |         transform: ['scale(1)', 'scale(1.25)']
129 |     }, 300);
130 |     el.style.transform = 'scale(1.25)';
131 | });
132 | el.addEventListener('mouseout', function () {
133 |     let anim = el.animate({
134 |         transform: ['scale(1.25)', 'scale(1)']
135 |     }, 300);
136 |     el.style.transform = '';
137 | });
138 | 
139 |
140 | 148 |
149 |
150 |
151 | 152 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /demos/accessibility.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Web Animation examples - Accessibility 4 | 5 | 6 | 7 | 84 | 85 | 86 |
87 |

Accessibility settings demo

88 |

Tweak the animations according to your needs an preferences. Some examples:

89 | 94 | 95 |
96 |
97 |
Jon Snow
98 |
Daenerys Targaryen
99 |
Tyrion Lannister
100 |
101 | 106 | 114 |
115 |
116 | 117 | 209 | 210 | -------------------------------------------------------------------------------- /styles.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic); 2 | 3 | :root { 4 | --contrast-color: #0095DD; 5 | --contrast-color-over: #00539F; 6 | --contrast-color-translucid: rgba(0, 149, 221, 0.7); 7 | --contrast-color-over-translucid: rgba(0, 83, 159, 0.7); 8 | 9 | --bg-color: #f6f4ec; 10 | --bg-color-shadow: #d7d3c8; 11 | 12 | --text-color: #000; 13 | --text-color-contrast: #fff; 14 | 15 | --highlight: rgba(255, 255, 255, 0.9); 16 | --highlight-subtle: rgba(255, 255, 255, 0.5); 17 | --shadow: rgba(0, 0, 0, 0.2); 18 | --dark-shadow: rgba(0, 0, 0, 0.6); 19 | } 20 | 21 | body { 22 | font-family: 'Open Sans', sans-serif; 23 | font-size: 14px; 24 | padding: 1em; 25 | margin: 0; 26 | line-height: 1.3em; 27 | background: linear-gradient(to top, var(--bg-color-shadow) 0%, var(--bg-color) 100%) center center repeat; 28 | } 29 | 30 | body, html { 31 | min-height: 100%; 32 | box-sizing: border-box; 33 | } 34 | 35 | code, pre { 36 | font-family: Courier, 'Courier New', monospace; 37 | font-size: 1rem; 38 | } 39 | 40 | code { 41 | color: #666; 42 | } 43 | 44 | a { 45 | color: var(--contrast-color); 46 | text-decoration: none; 47 | } 48 | 49 | a:hover { 50 | color: var(--contrast-color-over); 51 | text-decoration: underline; 52 | } 53 | 54 | a.button { 55 | display: inline-block; 56 | color: var(--text-color-contrast); 57 | text-decoration: none; 58 | line-height: 1.25rem; 59 | box-sizing: border-box; 60 | } 61 | 62 | button, a.button { 63 | border: 0; 64 | background: var(--contrast-color); 65 | font-size: 1rem; 66 | padding: 0.5rem 1rem; 67 | color: #fff; 68 | transition: background 0.2s ease; 69 | } 70 | 71 | button:active, button:hover, a.button:active, a.button:hover { 72 | background: var(--contrast-color-over); 73 | } 74 | 75 | button[disabled] { 76 | background: #ccc; 77 | color: #666; 78 | } 79 | 80 | button[disabled]:hover { 81 | cursor: not-allowed; 82 | } 83 | 84 | 85 | p, li { 86 | margin: 1em 0; 87 | } 88 | 89 | li, dt, dd { 90 | margin: 0.8em 0; 91 | } 92 | 93 | dd { 94 | margin-left: 2em; 95 | } 96 | 97 | input[type=range], input[type=color] { 98 | vertical-align: bottom; 99 | } 100 | 101 | h1, h2, h3 { 102 | font-weight: normal; 103 | text-shadow: 0 1px 0 var(--highlight); 104 | color: #484848; 105 | } 106 | 107 | h1 { 108 | font-size: 2em; 109 | line-height: 1.25em; 110 | } 111 | 112 | iframe { 113 | border: none; 114 | overflow: scroll; 115 | } 116 | 117 | /* ---------------------------------------------------------------------------*/ 118 | /* layout */ 119 | /* ---------------------------------------------------------------------------*/ 120 | 121 | body.index { 122 | padding: 0; 123 | margin: 0; 124 | min-height: 100vh; 125 | overflow: auto; 126 | } 127 | 128 | .page-wrapper { 129 | display: flex; 130 | align-items: stretch; 131 | min-height: 100vh; 132 | } 133 | 134 | .sidebar { 135 | flex: 0 0 auto; 136 | border-right: 4px solid var(--shadow); 137 | width: 280px; 138 | box-sizing: border-box; 139 | padding: 0em 1em 1em 1em; 140 | text-align: center; 141 | } 142 | 143 | .viewer-wrapper { 144 | flex: 1 1 auto; 145 | overflow: hidden; 146 | position: relative; 147 | } 148 | 149 | .viewer { 150 | margin: 0; 151 | padding: 0; 152 | height: 100%; 153 | box-sizing: border-box; 154 | width: 100%; 155 | position: absolute; /* chrome doesn't just like height:100% :( */ 156 | } 157 | 158 | /* helpers */ 159 | .panel { 160 | border-bottom: 2px solid var(--shadow); 161 | border-right: 2px solid var(--shadow); 162 | border-top: 2px solid var(--highlight); 163 | margin: 2em 0; 164 | padding: 1.5em; 165 | background: var(--bg-color); 166 | } 167 | 168 | .panel > *:first-child, .panel > header > * { 169 | margin-top: 0; 170 | } 171 | 172 | main.constrained { 173 | max-width: 900px; 174 | margin: 0 2em; 175 | } 176 | 177 | .burger { 178 | position: fixed; 179 | top: 0; 180 | left: 0; 181 | display: none; 182 | z-index: 10; 183 | } 184 | 185 | .burger button { 186 | padding: 0.2em; 187 | } 188 | 189 | .burger button, .view-source a { 190 | background: var(--contrast-color-translucid); 191 | } 192 | 193 | .burger button:hover, .view-source a:hover { 194 | background: var(--contrast-color-over-translucid); 195 | } 196 | 197 | .view-source { 198 | position: fixed; 199 | top: 0.5em; 200 | right: 0.5em; 201 | z-index: 10; 202 | display: none; 203 | } 204 | 205 | .view-source a:not(href~=http) { 206 | display: none; 207 | } 208 | 209 | @media (max-width: 900px) { 210 | .mobile-hidden { 211 | display: none; 212 | } 213 | 214 | .mobile-show { 215 | display: block; 216 | } 217 | 218 | .burger { 219 | display: block; 220 | } 221 | 222 | body { 223 | padding-top: 2em; 224 | } 225 | .page-wrapper { 226 | display: block; 227 | min-height: 0; 228 | } 229 | .sidebar { 230 | width: 100%; 231 | border: none; 232 | } 233 | .viewer-wrapper { 234 | height: 100vh; 235 | } 236 | .viewer-wrapper:not(.mobile-show) { 237 | display: none; 238 | } 239 | } 240 | 241 | /* ---------------------------------------------------------------------------*/ 242 | /* main menu */ 243 | /* ---------------------------------------------------------------------------*/ 244 | p.tagline { 245 | margin-top: -1em; 246 | } 247 | .menu { 248 | text-align: left; 249 | background: var(--bg-color); 250 | } 251 | 252 | .menu ul { 253 | padding-left: 0; 254 | } 255 | .menu li { 256 | display: block; 257 | line-height: 1.4em; 258 | border-bottom: 2px solid var(--shadow); 259 | border-top: 2px solid var(--highlight); 260 | margin: 0; 261 | } 262 | 263 | .menu a { 264 | padding: 1em; 265 | display: block; 266 | } 267 | 268 | .menu a:hover { 269 | text-decoration: none; 270 | background: var(--highlight-subtle); 271 | } 272 | 273 | .sidebar .button { 274 | width: 100%; 275 | } 276 | 277 | /* ---------------------------------------------------------------------------*/ 278 | /* custom tabzilla */ 279 | /* ---------------------------------------------------------------------------*/ 280 | 281 | #tabzilla { 282 | float: none; 283 | } 284 | 285 | #tabzilla a { 286 | box-shadow: none; 287 | margin: 0 auto; 288 | } 289 | 290 | #tabzilla a:hover { 291 | background-color: transparent; 292 | } 293 | 294 | #tabzilla:hover:before{ 295 | background-color: #C13832; 296 | } 297 | 298 | #tabzilla:before { 299 | background: #4D4E53; 300 | left: 50%; 301 | margin-left: -44px; 302 | } 303 | /* ---------------------------------------------------------------------------*/ 304 | /* no browser support warning banner 305 | /* ---------------------------------------------------------------------------*/ 306 | 307 | .no-support { 308 | background: var(--bg-color-shadow); 309 | padding: 1em; 310 | } 311 | 312 | /* ---------------------------------------------------------------------------*/ 313 | /* custom syntax highlight */ 314 | /* ---------------------------------------------------------------------------*/ 315 | pre[class*="language-"] { 316 | background: var(--highlight-subtle); 317 | margin: 1em 0; 318 | } 319 | -------------------------------------------------------------------------------- /demos/lib/prism.js: -------------------------------------------------------------------------------- 1 | /* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript */ 2 | var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(){var e=/\blang(?:uage)?-(\w+)\b/i,t=0,n=_self.Prism={util:{encode:function(e){return e instanceof a?new a(e.type,n.util.encode(e.content),e.alias):"Array"===n.util.type(e)?e.map(n.util.encode):e.replace(/&/g,"&").replace(/e.length)break e;if(!(v instanceof a)){u.lastIndex=0;var b=u.exec(v),k=1;if(!b&&h&&m!=r.length-1){if(u.lastIndex=y,b=u.exec(e),!b)break;for(var w=b.index+(g?b[1].length:0),_=b.index+b[0].length,A=m,S=y,P=r.length;P>A&&_>S;++A)S+=(r[A].matchedStr||r[A]).length,w>=S&&(++m,y=S);if(r[m]instanceof a||r[A-1].greedy)continue;k=A-m,v=e.slice(y,S),b.index-=y}if(b){g&&(f=b[1].length);var w=b.index+f,b=b[0].slice(f),_=w+b.length,x=v.slice(0,w),O=v.slice(_),j=[m,k];x&&j.push(x);var N=new a(l,c?n.tokenize(b,c):b,d,b,h);j.push(N),O&&j.push(O),Array.prototype.splice.apply(r,j)}}}}}return r},hooks:{all:{},add:function(e,t){var a=n.hooks.all;a[e]=a[e]||[],a[e].push(t)},run:function(e,t){var a=n.hooks.all[e];if(a&&a.length)for(var r,i=0;r=a[i++];)r(t)}}},a=n.Token=function(e,t,n,a,r){this.type=e,this.content=t,this.alias=n,this.matchedStr=a||null,this.greedy=!!r};if(a.stringify=function(e,t,r){if("string"==typeof e)return e;if("Array"===n.util.type(e))return e.map(function(n){return a.stringify(n,t,e)}).join("");var i={type:e.type,content:a.stringify(e.content,t,r),tag:"span",classes:["token",e.type],attributes:{},language:t,parent:r};if("comment"==i.type&&(i.attributes.spellcheck="true"),e.alias){var l="Array"===n.util.type(e.alias)?e.alias:[e.alias];Array.prototype.push.apply(i.classes,l)}n.hooks.run("wrap",i);var o="";for(var s in i.attributes)o+=(o?" ":"")+s+'="'+(i.attributes[s]||"")+'"';return"<"+i.tag+' class="'+i.classes.join(" ")+'"'+(o?" "+o:"")+">"+i.content+""},!_self.document)return _self.addEventListener?(_self.addEventListener("message",function(e){var t=JSON.parse(e.data),a=t.language,r=t.code,i=t.immediateClose;_self.postMessage(n.highlight(r,n.languages[a],a)),i&&_self.close()},!1),_self.Prism):_self.Prism;var r=document.currentScript||[].slice.call(document.getElementsByTagName("script")).pop();return r&&(n.filename=r.src,document.addEventListener&&!r.hasAttribute("data-manual")&&("loading"!==document.readyState?window.requestAnimationFrame?window.requestAnimationFrame(n.highlightAll):window.setTimeout(n.highlightAll,16):document.addEventListener("DOMContentLoaded",n.highlightAll))),_self.Prism}();"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); 3 | Prism.languages.markup={comment://,prolog:/<\?[\w\W]+?\?>/,doctype://,cdata://i,tag:{pattern:/<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,inside:{tag:{pattern:/^<\/?[^\s>\/]+/i,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,inside:{punctuation:/[=>"']/}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:/&#?[\da-z]{1,8};/i},Prism.hooks.add("wrap",function(a){"entity"===a.type&&(a.attributes.title=a.content.replace(/&/,"&"))}),Prism.languages.xml=Prism.languages.markup,Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup; 4 | Prism.languages.css={comment:/\/\*[\w\W]*?\*\//,atrule:{pattern:/@[\w-]+?.*?(;|(?=\s*\{))/i,inside:{rule:/@[\w-]+/}},url:/url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,selector:/[^\{\}\s][^\{\};]*?(?=\s*\{)/,string:/("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,property:/(\b|\B)[\w-]+(?=\s*:)/i,important:/\B!important\b/i,"function":/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:]/},Prism.languages.css.atrule.inside.rest=Prism.util.clone(Prism.languages.css),Prism.languages.markup&&(Prism.languages.insertBefore("markup","tag",{style:{pattern:/()[\w\W]*?(?=<\/style>)/i,lookbehind:!0,inside:Prism.languages.css,alias:"language-css"}}),Prism.languages.insertBefore("inside","attr-value",{"style-attr":{pattern:/\s*style=("|').*?\1/i,inside:{"attr-name":{pattern:/^\s*style/i,inside:Prism.languages.markup.tag.inside},punctuation:/^\s*=\s*['"]|['"]\s*$/,"attr-value":{pattern:/.+/i,inside:Prism.languages.css}},alias:"language-css"}},Prism.languages.markup.tag)); 5 | Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\w\W]*?\*\//,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],string:{pattern:/(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,lookbehind:!0,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,"boolean":/\b(true|false)\b/,"function":/[a-z0-9_]+(?=\()/i,number:/\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,punctuation:/[{}[\];(),.:]/}; 6 | Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,number:/\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,"function":/[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*\*?|\/|~|\^|%|\.{3}/}),Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/(^|[^\/])\/(?!\/)(\[.+?]|\\.|[^\/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,lookbehind:!0,greedy:!0}}),Prism.languages.insertBefore("javascript","string",{"template-string":{pattern:/`(?:\\\\|\\?[^\\])*?`/,greedy:!0,inside:{interpolation:{pattern:/\$\{[^}]+\}/,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:Prism.languages.javascript}},string:/[\s\S]+/}}}),Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{script:{pattern:/()[\w\W]*?(?=<\/script>)/i,lookbehind:!0,inside:Prism.languages.javascript,alias:"language-javascript"}}),Prism.languages.js=Prism.languages.javascript; 7 | -------------------------------------------------------------------------------- /demos/style-guide.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Web Animations examples 5 | 6 | 7 | 29 | 30 | 174 | 175 | 176 |
177 |

Style guide

178 |

Tweak each UX component and adjust its animations.

179 |
180 |

Expand Element Config

181 |

Use to expand an element in order to reveal more content to the user.

182 | 183 |
184 |

185 | 186 | 188 |

189 | 190 |

191 | 192 | 194 |

195 | 196 |

204 |

212 |
213 | 214 |
215 |

Here is lots of content which can be expanded

216 |

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur finibus nisi at massa accumsan, et aliquet lacus consequat. Proin ultricies leo augue, dignissim placerat ipsum imperdiet sit amet. Nullam iaculis neque ac eros dapibus, vitae pellentesque eros faucibus. Curabitur dignissim lobortis tortor, in viverra nisi congue sit amet.

217 |
218 |
219 | 220 |
221 |

Button Suggest Action Config

222 |

Use to suggest a button action to the user by drawing attention to it.

223 | 224 |

225 | 226 |

227 |

229 |

230 | 231 |

232 |
233 |
234 | 235 |
236 |

Element Fade In Config

237 |

Use to introduce a dynamically loaded piece of content to the user.

238 | 239 |
240 |

Dynamically Fetched Content

241 |

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed lacinia sed sapien vehicula vestibulum.

242 |
243 | 244 |
245 |

246 | 247 | 248 |

249 |
250 |
251 |
252 | 253 | 254 | -------------------------------------------------------------------------------- /demos/lib/Tween.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Tween.js - Licensed under the MIT license 3 | * https://github.com/tweenjs/tween.js 4 | * ---------------------------------------------- 5 | * 6 | * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors. 7 | * Thank you all, you're awesome! 8 | */ 9 | 10 | // Include a performance.now polyfill 11 | (function () { 12 | 13 | if ('performance' in window === false) { 14 | window.performance = {}; 15 | } 16 | 17 | // IE 8 18 | Date.now = (Date.now || function () { 19 | return new Date().getTime(); 20 | }); 21 | 22 | if ('now' in window.performance === false) { 23 | var offset = window.performance.timing && window.performance.timing.navigationStart ? window.performance.timing.navigationStart 24 | : Date.now(); 25 | 26 | window.performance.now = function () { 27 | return Date.now() - offset; 28 | }; 29 | } 30 | 31 | })(); 32 | 33 | var TWEEN = TWEEN || (function () { 34 | 35 | var _tweens = []; 36 | 37 | return { 38 | 39 | getAll: function () { 40 | 41 | return _tweens; 42 | 43 | }, 44 | 45 | removeAll: function () { 46 | 47 | _tweens = []; 48 | 49 | }, 50 | 51 | add: function (tween) { 52 | 53 | _tweens.push(tween); 54 | 55 | }, 56 | 57 | remove: function (tween) { 58 | 59 | var i = _tweens.indexOf(tween); 60 | 61 | if (i !== -1) { 62 | _tweens.splice(i, 1); 63 | } 64 | 65 | }, 66 | 67 | update: function (time) { 68 | 69 | if (_tweens.length === 0) { 70 | return false; 71 | } 72 | 73 | var i = 0; 74 | 75 | time = time !== undefined ? time : window.performance.now(); 76 | 77 | while (i < _tweens.length) { 78 | 79 | if (_tweens[i].update(time)) { 80 | i++; 81 | } else { 82 | _tweens.splice(i, 1); 83 | } 84 | 85 | } 86 | 87 | return true; 88 | 89 | } 90 | }; 91 | 92 | })(); 93 | 94 | TWEEN.Tween = function (object) { 95 | 96 | var _object = object; 97 | var _valuesStart = {}; 98 | var _valuesEnd = {}; 99 | var _valuesStartRepeat = {}; 100 | var _duration = 1000; 101 | var _repeat = 0; 102 | var _yoyo = false; 103 | var _isPlaying = false; 104 | var _reversed = false; 105 | var _delayTime = 0; 106 | var _startTime = null; 107 | var _easingFunction = TWEEN.Easing.Linear.None; 108 | var _interpolationFunction = TWEEN.Interpolation.Linear; 109 | var _chainedTweens = []; 110 | var _onStartCallback = null; 111 | var _onStartCallbackFired = false; 112 | var _onUpdateCallback = null; 113 | var _onCompleteCallback = null; 114 | var _onStopCallback = null; 115 | 116 | // Set all starting values present on the target object 117 | for (var field in object) { 118 | _valuesStart[field] = parseFloat(object[field], 10); 119 | } 120 | 121 | this.to = function (properties, duration) { 122 | 123 | if (duration !== undefined) { 124 | _duration = duration; 125 | } 126 | 127 | _valuesEnd = properties; 128 | 129 | return this; 130 | 131 | }; 132 | 133 | this.start = function (time) { 134 | 135 | TWEEN.add(this); 136 | 137 | _isPlaying = true; 138 | 139 | _onStartCallbackFired = false; 140 | 141 | _startTime = time !== undefined ? time : window.performance.now(); 142 | _startTime += _delayTime; 143 | 144 | for (var property in _valuesEnd) { 145 | 146 | // Check if an Array was provided as property value 147 | if (_valuesEnd[property] instanceof Array) { 148 | 149 | if (_valuesEnd[property].length === 0) { 150 | continue; 151 | } 152 | 153 | // Create a local copy of the Array with the start value at the front 154 | _valuesEnd[property] = [_object[property]].concat(_valuesEnd[property]); 155 | 156 | } 157 | 158 | // If `to()` specifies a property that doesn't exist in the source object, 159 | // we should not set that property in the object 160 | if (_valuesStart[property] === undefined) { 161 | continue; 162 | } 163 | 164 | _valuesStart[property] = _object[property]; 165 | 166 | if ((_valuesStart[property] instanceof Array) === false) { 167 | _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings 168 | } 169 | 170 | _valuesStartRepeat[property] = _valuesStart[property] || 0; 171 | 172 | } 173 | 174 | return this; 175 | 176 | }; 177 | 178 | this.stop = function () { 179 | 180 | if (!_isPlaying) { 181 | return this; 182 | } 183 | 184 | TWEEN.remove(this); 185 | _isPlaying = false; 186 | 187 | if (_onStopCallback !== null) { 188 | _onStopCallback.call(_object); 189 | } 190 | 191 | this.stopChainedTweens(); 192 | return this; 193 | 194 | }; 195 | 196 | this.stopChainedTweens = function () { 197 | 198 | for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) { 199 | _chainedTweens[i].stop(); 200 | } 201 | 202 | }; 203 | 204 | this.delay = function (amount) { 205 | 206 | _delayTime = amount; 207 | return this; 208 | 209 | }; 210 | 211 | this.repeat = function (times) { 212 | 213 | _repeat = times; 214 | return this; 215 | 216 | }; 217 | 218 | this.yoyo = function (yoyo) { 219 | 220 | _yoyo = yoyo; 221 | return this; 222 | 223 | }; 224 | 225 | 226 | this.easing = function (easing) { 227 | 228 | _easingFunction = easing; 229 | return this; 230 | 231 | }; 232 | 233 | this.interpolation = function (interpolation) { 234 | 235 | _interpolationFunction = interpolation; 236 | return this; 237 | 238 | }; 239 | 240 | this.chain = function () { 241 | 242 | _chainedTweens = arguments; 243 | return this; 244 | 245 | }; 246 | 247 | this.onStart = function (callback) { 248 | 249 | _onStartCallback = callback; 250 | return this; 251 | 252 | }; 253 | 254 | this.onUpdate = function (callback) { 255 | 256 | _onUpdateCallback = callback; 257 | return this; 258 | 259 | }; 260 | 261 | this.onComplete = function (callback) { 262 | 263 | _onCompleteCallback = callback; 264 | return this; 265 | 266 | }; 267 | 268 | this.onStop = function (callback) { 269 | 270 | _onStopCallback = callback; 271 | return this; 272 | 273 | }; 274 | 275 | this.update = function (time) { 276 | 277 | var property; 278 | var elapsed; 279 | var value; 280 | 281 | if (time < _startTime) { 282 | return true; 283 | } 284 | 285 | if (_onStartCallbackFired === false) { 286 | 287 | if (_onStartCallback !== null) { 288 | _onStartCallback.call(_object); 289 | } 290 | 291 | _onStartCallbackFired = true; 292 | 293 | } 294 | 295 | elapsed = (time - _startTime) / _duration; 296 | elapsed = elapsed > 1 ? 1 : elapsed; 297 | 298 | value = _easingFunction(elapsed); 299 | 300 | for (property in _valuesEnd) { 301 | 302 | // Don't update properties that do not exist in the source object 303 | if (_valuesStart[property] === undefined) { 304 | continue; 305 | } 306 | 307 | var start = _valuesStart[property] || 0; 308 | var end = _valuesEnd[property]; 309 | 310 | if (end instanceof Array) { 311 | 312 | _object[property] = _interpolationFunction(end, value); 313 | 314 | } else { 315 | 316 | // Parses relative end values with start as base (e.g.: +10, -3) 317 | if (typeof (end) === 'string') { 318 | 319 | if (end.startsWith('+') || end.startsWith('-')) { 320 | end = start + parseFloat(end, 10); 321 | } else { 322 | end = parseFloat(end, 10); 323 | } 324 | } 325 | 326 | // Protect against non numeric properties. 327 | if (typeof (end) === 'number') { 328 | _object[property] = start + (end - start) * value; 329 | } 330 | 331 | } 332 | 333 | } 334 | 335 | if (_onUpdateCallback !== null) { 336 | _onUpdateCallback.call(_object, value); 337 | } 338 | 339 | if (elapsed === 1) { 340 | 341 | if (_repeat > 0) { 342 | 343 | if (isFinite(_repeat)) { 344 | _repeat--; 345 | } 346 | 347 | // Reassign starting values, restart by making startTime = now 348 | for (property in _valuesStartRepeat) { 349 | 350 | if (typeof (_valuesEnd[property]) === 'string') { 351 | _valuesStartRepeat[property] = _valuesStartRepeat[property] + parseFloat(_valuesEnd[property], 10); 352 | } 353 | 354 | if (_yoyo) { 355 | var tmp = _valuesStartRepeat[property]; 356 | 357 | _valuesStartRepeat[property] = _valuesEnd[property]; 358 | _valuesEnd[property] = tmp; 359 | } 360 | 361 | _valuesStart[property] = _valuesStartRepeat[property]; 362 | 363 | } 364 | 365 | if (_yoyo) { 366 | _reversed = !_reversed; 367 | } 368 | 369 | _startTime = time + _delayTime; 370 | 371 | return true; 372 | 373 | } else { 374 | 375 | if (_onCompleteCallback !== null) { 376 | _onCompleteCallback.call(_object); 377 | } 378 | 379 | for (var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++) { 380 | // Make the chained tweens start exactly at the time they should, 381 | // even if the `update()` method was called way past the duration of the tween 382 | _chainedTweens[i].start(_startTime + _duration); 383 | } 384 | 385 | return false; 386 | 387 | } 388 | 389 | } 390 | 391 | return true; 392 | 393 | }; 394 | 395 | }; 396 | 397 | 398 | TWEEN.Easing = { 399 | 400 | Linear: { 401 | 402 | None: function (k) { 403 | 404 | return k; 405 | 406 | } 407 | 408 | }, 409 | 410 | Quadratic: { 411 | 412 | In: function (k) { 413 | 414 | return k * k; 415 | 416 | }, 417 | 418 | Out: function (k) { 419 | 420 | return k * (2 - k); 421 | 422 | }, 423 | 424 | InOut: function (k) { 425 | 426 | if ((k *= 2) < 1) { 427 | return 0.5 * k * k; 428 | } 429 | 430 | return - 0.5 * (--k * (k - 2) - 1); 431 | 432 | } 433 | 434 | }, 435 | 436 | Cubic: { 437 | 438 | In: function (k) { 439 | 440 | return k * k * k; 441 | 442 | }, 443 | 444 | Out: function (k) { 445 | 446 | return --k * k * k + 1; 447 | 448 | }, 449 | 450 | InOut: function (k) { 451 | 452 | if ((k *= 2) < 1) { 453 | return 0.5 * k * k * k; 454 | } 455 | 456 | return 0.5 * ((k -= 2) * k * k + 2); 457 | 458 | } 459 | 460 | }, 461 | 462 | Quartic: { 463 | 464 | In: function (k) { 465 | 466 | return k * k * k * k; 467 | 468 | }, 469 | 470 | Out: function (k) { 471 | 472 | return 1 - (--k * k * k * k); 473 | 474 | }, 475 | 476 | InOut: function (k) { 477 | 478 | if ((k *= 2) < 1) { 479 | return 0.5 * k * k * k * k; 480 | } 481 | 482 | return - 0.5 * ((k -= 2) * k * k * k - 2); 483 | 484 | } 485 | 486 | }, 487 | 488 | Quintic: { 489 | 490 | In: function (k) { 491 | 492 | return k * k * k * k * k; 493 | 494 | }, 495 | 496 | Out: function (k) { 497 | 498 | return --k * k * k * k * k + 1; 499 | 500 | }, 501 | 502 | InOut: function (k) { 503 | 504 | if ((k *= 2) < 1) { 505 | return 0.5 * k * k * k * k * k; 506 | } 507 | 508 | return 0.5 * ((k -= 2) * k * k * k * k + 2); 509 | 510 | } 511 | 512 | }, 513 | 514 | Sinusoidal: { 515 | 516 | In: function (k) { 517 | 518 | return 1 - Math.cos(k * Math.PI / 2); 519 | 520 | }, 521 | 522 | Out: function (k) { 523 | 524 | return Math.sin(k * Math.PI / 2); 525 | 526 | }, 527 | 528 | InOut: function (k) { 529 | 530 | return 0.5 * (1 - Math.cos(Math.PI * k)); 531 | 532 | } 533 | 534 | }, 535 | 536 | Exponential: { 537 | 538 | In: function (k) { 539 | 540 | return k === 0 ? 0 : Math.pow(1024, k - 1); 541 | 542 | }, 543 | 544 | Out: function (k) { 545 | 546 | return k === 1 ? 1 : 1 - Math.pow(2, - 10 * k); 547 | 548 | }, 549 | 550 | InOut: function (k) { 551 | 552 | if (k === 0) { 553 | return 0; 554 | } 555 | 556 | if (k === 1) { 557 | return 1; 558 | } 559 | 560 | if ((k *= 2) < 1) { 561 | return 0.5 * Math.pow(1024, k - 1); 562 | } 563 | 564 | return 0.5 * (- Math.pow(2, - 10 * (k - 1)) + 2); 565 | 566 | } 567 | 568 | }, 569 | 570 | Circular: { 571 | 572 | In: function (k) { 573 | 574 | return 1 - Math.sqrt(1 - k * k); 575 | 576 | }, 577 | 578 | Out: function (k) { 579 | 580 | return Math.sqrt(1 - (--k * k)); 581 | 582 | }, 583 | 584 | InOut: function (k) { 585 | 586 | if ((k *= 2) < 1) { 587 | return - 0.5 * (Math.sqrt(1 - k * k) - 1); 588 | } 589 | 590 | return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1); 591 | 592 | } 593 | 594 | }, 595 | 596 | Elastic: { 597 | 598 | In: function (k) { 599 | 600 | if (k === 0) { 601 | return 0; 602 | } 603 | 604 | if (k === 1) { 605 | return 1; 606 | } 607 | 608 | return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); 609 | 610 | }, 611 | 612 | Out: function (k) { 613 | 614 | if (k === 0) { 615 | return 0; 616 | } 617 | 618 | if (k === 1) { 619 | return 1; 620 | } 621 | 622 | return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1; 623 | 624 | }, 625 | 626 | InOut: function (k) { 627 | 628 | if (k === 0) { 629 | return 0; 630 | } 631 | 632 | if (k === 1) { 633 | return 1; 634 | } 635 | 636 | k *= 2; 637 | 638 | if (k < 1) { 639 | return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); 640 | } 641 | 642 | return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1; 643 | 644 | } 645 | 646 | }, 647 | 648 | Back: { 649 | 650 | In: function (k) { 651 | 652 | var s = 1.70158; 653 | 654 | return k * k * ((s + 1) * k - s); 655 | 656 | }, 657 | 658 | Out: function (k) { 659 | 660 | var s = 1.70158; 661 | 662 | return --k * k * ((s + 1) * k + s) + 1; 663 | 664 | }, 665 | 666 | InOut: function (k) { 667 | 668 | var s = 1.70158 * 1.525; 669 | 670 | if ((k *= 2) < 1) { 671 | return 0.5 * (k * k * ((s + 1) * k - s)); 672 | } 673 | 674 | return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2); 675 | 676 | } 677 | 678 | }, 679 | 680 | Bounce: { 681 | 682 | In: function (k) { 683 | 684 | return 1 - TWEEN.Easing.Bounce.Out(1 - k); 685 | 686 | }, 687 | 688 | Out: function (k) { 689 | 690 | if (k < (1 / 2.75)) { 691 | return 7.5625 * k * k; 692 | } else if (k < (2 / 2.75)) { 693 | return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75; 694 | } else if (k < (2.5 / 2.75)) { 695 | return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375; 696 | } else { 697 | return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375; 698 | } 699 | 700 | }, 701 | 702 | InOut: function (k) { 703 | 704 | if (k < 0.5) { 705 | return TWEEN.Easing.Bounce.In(k * 2) * 0.5; 706 | } 707 | 708 | return TWEEN.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5; 709 | 710 | } 711 | 712 | } 713 | 714 | }; 715 | 716 | TWEEN.Interpolation = { 717 | 718 | Linear: function (v, k) { 719 | 720 | var m = v.length - 1; 721 | var f = m * k; 722 | var i = Math.floor(f); 723 | var fn = TWEEN.Interpolation.Utils.Linear; 724 | 725 | if (k < 0) { 726 | return fn(v[0], v[1], f); 727 | } 728 | 729 | if (k > 1) { 730 | return fn(v[m], v[m - 1], m - f); 731 | } 732 | 733 | return fn(v[i], v[i + 1 > m ? m : i + 1], f - i); 734 | 735 | }, 736 | 737 | Bezier: function (v, k) { 738 | 739 | var b = 0; 740 | var n = v.length - 1; 741 | var pw = Math.pow; 742 | var bn = TWEEN.Interpolation.Utils.Bernstein; 743 | 744 | for (var i = 0; i <= n; i++) { 745 | b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i); 746 | } 747 | 748 | return b; 749 | 750 | }, 751 | 752 | CatmullRom: function (v, k) { 753 | 754 | var m = v.length - 1; 755 | var f = m * k; 756 | var i = Math.floor(f); 757 | var fn = TWEEN.Interpolation.Utils.CatmullRom; 758 | 759 | if (v[0] === v[m]) { 760 | 761 | if (k < 0) { 762 | i = Math.floor(f = m * (1 + k)); 763 | } 764 | 765 | return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i); 766 | 767 | } else { 768 | 769 | if (k < 0) { 770 | return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]); 771 | } 772 | 773 | if (k > 1) { 774 | return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]); 775 | } 776 | 777 | return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i); 778 | 779 | } 780 | 781 | }, 782 | 783 | Utils: { 784 | 785 | Linear: function (p0, p1, t) { 786 | 787 | return (p1 - p0) * t + p0; 788 | 789 | }, 790 | 791 | Bernstein: function (n, i) { 792 | 793 | var fc = TWEEN.Interpolation.Utils.Factorial; 794 | 795 | return fc(n) / fc(i) / fc(n - i); 796 | 797 | }, 798 | 799 | Factorial: (function () { 800 | 801 | var a = [1]; 802 | 803 | return function (n) { 804 | 805 | var s = 1; 806 | 807 | if (a[n]) { 808 | return a[n]; 809 | } 810 | 811 | for (var i = n; i > 1; i--) { 812 | s *= i; 813 | } 814 | 815 | a[n] = s; 816 | return s; 817 | 818 | }; 819 | 820 | })(), 821 | 822 | CatmullRom: function (p0, p1, p2, p3, t) { 823 | 824 | var v0 = (p2 - p0) * 0.5; 825 | var v1 = (p3 - p1) * 0.5; 826 | var t2 = t * t; 827 | var t3 = t * t2; 828 | 829 | return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (- 3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1; 830 | 831 | } 832 | 833 | } 834 | 835 | }; 836 | 837 | // UMD (Universal Module Definition) 838 | (function (root) { 839 | 840 | if (typeof define === 'function' && define.amd) { 841 | 842 | // AMD 843 | define([], function () { 844 | return TWEEN; 845 | }); 846 | 847 | } else if (typeof module !== 'undefined' && typeof exports === 'object') { 848 | 849 | // Node.js 850 | module.exports = TWEEN; 851 | 852 | } else if (root !== undefined) { 853 | 854 | // Global variable 855 | root.TWEEN = TWEEN; 856 | 857 | } 858 | 859 | })(this); 860 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | --------------------------------------------------------------------------------