源码,懒得优化了,自己整理吧,态乱了
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 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 | <!DOCTYPE html> < html > < head > < title >粽子节</ title > < meta charset = "UTF-8" > </ head > < style type = "text/css" > /*动画样式*/ @-webkit-keyframes rock{ 0%{ transform:rotate(0deg);} 10%{ transform:rotate(3deg);} 20%{ transform:rotate(-3deg);} 30%{ transform:rotate(2deg);} 40%{ transform:rotate(-2deg);} 50%{ transform:rotate(1deg);} 60%{ transform:rotate(-1deg);} 70%{ transform:rotate(0deg);} 100%{ transform:rotate(0deg);} } *{ padding: 0; margin: 0; } body{ background: #000; min-height: 600px; min-width: 1200px; -webkit-font-smoothing:antialisased; font-family: 'WenQuanYi Micro Hei', SimSun, sans-serif; } .main{ width: 1200px; height: 600px; background: url(img/bg.jpg); position: absolute; left: 50%; top: 50%; margin-left: -600px; margin-top: -300px; overflow: hidden; } /*粽子盒子*/ .c_zongzi_box{ width: 312px; height: 305px; position: absolute; left: 700px; top: 184px; cursor: pointer; } .c_rock{ -webkit-animation:rock 2s infinite; } .c_zongzi{ width: 312px; height: 305px; background: url(img/zz.png); transition: all 1s; } .c_zongzi_out{ opacity: 0; transform: scale(0.5); } /*part1绳子下来*/ .c_shengzi_1{ width: 218px; height: 180px; position: absolute; background: url(img/line_1.png); left: 10px; top: 120px; z-index: 999; transform:all 0.5s; } .c_shengzi_2{ width: 219px; height: 159px; position: absolute; background: url(img/line_2.png); left: 10px; top: 158px; } .c_shengzi_3{ width: 264px; height: 117px; position: absolute; background: url(img/line_3.png); left: 10px; top: 220px; } .c_shengzi_4{ width: 288px; height: 56px; position: absolute; background: url(img/line_4.png); left: 10px; top: 290px; } /*part2粽子肉出场*/ .c_zongzirou{ width: 288px; height: 206px; position: absolute; background-image: url(img/zzr_1.png); background-size: 288px 206px; left: 50px; top: 54px; z-index: 110; opacity: 0; transform-origin: center center; transform: scale(0.8); } .c_zongzirou_in{ opacity: 1; transform: scale(1); } .c_zongzirou_ins{ transition: all 1s; } .c_zongzirou2{ transform:rotateX(180deg) rotateY(180deg) scale(1,0); z-index: 100; transform-origin:center bottom; width: 288px; height: 206px; position: absolute; background-image: url(img/zzr_1.png); background-size: 288px 206px; left: 50px; bottom: 45px; opacity: 0; } /*part2-3左边叶子*/ .c_zuoye{ width: 114px; height: 266px; position: absolute; background: url(img/leaf_left.png); left: 0px; top: -30px; z-index: 201; opacity: 0; transform-origin: left bottom; } .c_zuoye_in{ opacity: 1; transform:rotate(-5deg); transition:all 2s; } .c_zuoye_out{ opacity: 0; transform:rotate(-15deg); transition:all 1s; } /*part2-3右边叶子*/ .c_youye{ width: 318px; height: 338px; position: absolute; background: url(img/leaf_right.png); left: 80px; top: -60px; z-index: 201; opacity: 0; transform-origin: left bottom; transform:scale(0.8); } .c_youye_in{ opacity: 1; transform:rotate(5deg) scale(0.8); transition:all 2s; } .c_youye_out{ opacity: 0; transform:rotate(15deg) scale(0.8); transition:all 1s; } /*part4下面的叶子*/ .c_diye{ width: 618px; height: 468px; position: absolute; background: url(img/leaf_expand.png); left: -110px; top: -43px; z-index: 99; opacity: 0; transition:all 1s; } .c_diye_in{ opacity: 1; } /*文字*/ .c_t_1{ width: 180px; height: 100px; position: absolute; background: url(img/t_jixiang.png); left: 50%; top: 50%; margin-left: -50px; margin-top: -30px; z-index: 900; transform-origin:center center; transform:scale(0.8); opacity: 0; } .c_t_2{ width: 180px; height: 100px; position: absolute; background: url(img/t_ruyi.png); left: 50%; top: 50%; margin-left: -50px; margin-top: -30px; z-index: 200; transform-origin:center center; transform:scale(0.8); opacity: 0; } .c_t_3{ width: 180px; height: 100px; position: absolute; background: url(img/t_haoyun.png); left: 50%; top: 50%; margin-left: -50px; margin-top: -30px; z-index: 200; opacity: 0; transform:scale(0.8,0); transform-origin:center bottom; } .c_t_in{ opacity: 1; } .c_t_ins{ transition:all 1s; } /*粽子肉旋转*/ .c_zongzirou_view2{ background-image: url(img/zzr_2.png); } .c_zongzirou_view3{ background-image: url(img/zzr_3.png); } .c_zongzirou_view4{ background-image: url(img/zzr_4.png); } /*粽子肉翻转*/ .c_zongzirou_v1{ opacity: 1; transform:scale(1,0.85) translate(0,-15px); } .c_zongzirou_v2{ opacity: 1; transform:scale(1,0.65) translate(0,-50px); } .c_zongzirou_v3{ opacity: 1; transform:scale(1,0.45) translate(0,-120px); } .c_zongzirou_v4{ opacity: 1; transform:scale(1,0); } .c_zongzirou2_v1{ opacity: 1; transform:rotate(180deg) scale(1,0.45) translate(0,180px); } .c_zongzirou2_v2{ opacity: 1; transform:rotate(180deg) scale(1,0.65) translate(0,185px); } .c_zongzirou2_v3{ opacity: 1; transform:rotate(180deg) scale(1,0.85) translate(0,190px); } .c_zongzirou2_v4{ opacity: 1; transform:rotate(180deg) scale(1,1) translate(0,195px); } /*文字的视角*/ .c_t_v0{ transform:scale(0.8); } .c_t_m0{ display: none; } .c_t_v2{ transform:scale(0.8) rotateY(30deg) translate(-50px, 0) rotate(8deg); } .c_t_m2{ transform:scale(0.7) rotateY(70deg) translate(283px, -15px) rotate(-8deg); } .c_t_v3{ transform:scale(0.75) rotateY(49deg) translate(-94px, 0) rotate(15deg); } .c_t_m3{ transform:scale(0.75) rotateY(49deg) translate(118px, 0) rotate(-15deg); } .c_t_v4{ transform:scale(0.6) rotateY(50deg) translate(-196px, 10px) rotate(24deg); } .c_t_m4{ transform:scale(0.8) rotateY(30deg) translate(58px, 10px) rotate(-5deg); } .c_t_t1{ opacity: 1; transform:scale(0.6,0.25) translate(0,150px); } .c_t_t2{ opacity: 1; transform:scale(0.7,0.4) translate(0,40px); } .c_t_t3{ opacity: 1; transform:scale(0.8,0.6) translate(0,15px); } .c_t_t4{ opacity: 1; transform:scale(0.8) translate(0,-10px); } .c_t_tx1{ opacity: 1; transform:scale(0.8,0.6) translate(0,-50px); } .c_t_tx2{ opacity: 1; transform:scale(0.7,0.4) translate(0,-150px); } .c_t_tx3{ opacity: 1; transform:scale(0.6,0.25) translate(0,-300px); } .c_t_tx4{ transform:scale(0); } /*说明*/ .text{ position: absolute; width: 400px; height: 370px; left: 180px; top: 140px; font-size: 14px; line-height: 20px; color: #333; opacity: 0; } .text_in{ opacity: 1; transition:all 1s; } .text .caption{ width: 400px; height: 240px; background: url(img/caption.png) no-repeat; margin-left: 40px; opacity: 0; transition:all 1s; } .text .caption_rock{ -webkit-animation:rock 4s infinite; } .text .to{ width: 400px; margin-top: 10px; margin-left: 40px; opacity: 0; transition:all 1s 0.5s; } .text .msg{ width: 400px; margin-top: 10px; margin-left: 40px; opacity: 0; transition:all 1s 1s; } .text .from{ width: 400px; margin-top: 10px; margin-left: 40px; text-align: right; opacity: 0; transition:all 1s 1.5s; } .text_in .caption, .text_in .to, .text_in .msg, .text_in .from{ opacity: 1; margin-left: 0; } </ style > < body > < div class = "main" > < div class = "c_zongzi_box" id = "c_zongzi_box" > < div class = "c_zongzi" id = "c_zongzi" ></ div > < div class = "c_shengzi_1" id = "c_shengzi_1" ></ div > <!--此处是打开后!--> < div class = "c_zongzirou" id = "c_zongzirou" ></ div > < div class = "c_zongzirou2" id = "c_zongzirou2" ></ div > < div class = "c_zuoye" id = "c_zuoye" ></ div > < div class = "c_youye" id = "c_youye" ></ div > < div class = "c_diye" id = "c_diye" ></ div > <!--此处是打开后文字!--> < div class = "c_t_1" id = "c_t_1" ></ div > < div class = "c_t_2" id = "c_t_2" ></ div > < div class = "c_t_3" id = "c_t_3" ></ div > </ div > <!--祝福文字!--> < div class = "text" id = "text" > < div class = "caption" id = "caption" ></ div > < div class = "to" >A:</ div > < div class = "msg" >hello</ div > < div class = "from" >B</ div > </ div > </ div > < script type = "text/javascript" > var g=function(id){ return document.getElementById(id); }; //时间类函数 var Timeline=function(){ this.order=[];//动画序列 this.add=function(timeout,func,log){ this.order.push({ timeout:timeout, func:func, log:log }); //支持快进 this.start=function(ff){ for (var i in this.order){ (function(me){ var fn=me.func, timeout=me.timeout, log=me.log; timeout=Math.max(timeout-(ff||0),0); setTimeout(fn,timeout); setTimeout(function(){ console.log('time:',timeout,'log:',log); },timeout); })(this.order[i]); } }; }; }; //操作行为 var s=new Timeline(); var s2=new Timeline(); var s3=new Timeline(); var s4=new Timeline(); //入场动画 s.add(0,function(){ g('c_zongzi_box').className='c_zongzi_box c_rock'; g('c_shengzi_1').onclick=function(){ s2.start(); }; },'抖动了'); //点击后 s2.add(0,function(){ g('c_zongzi_box').className='c_zongzi_box'; g('text').className='text text_in'; },'动画开始了,我也不抖了'); s2.add(100,function(){ g('c_shengzi_1').className='c_shengzi_2'; },'绳子2了'); s2.add(600,function(){ g('c_shengzi_1').className='c_shengzi_3'; },'绳子3了'); s2.add(1100,function(){ g('c_shengzi_1').className='c_shengzi_4'; g('caption').className='caption caption_rock'; },'绳子4了'); s2.add(2100,function(){ g('c_zongzi').className='c_zongzi_out'; g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_ins'; g('c_zuoye').className='c_zuoye c_zuoye_in'; g('c_youye').className='c_youye c_youye_in'; g('c_t_1').className='c_t_1 c_t_in c_t_ins'; },'皮换肉了,叶子和字出来'); s2.add(3600,function(){ g('c_zuoye').className='c_zuoye c_zuoye_in c_zuoye_out'; g('c_youye').className='c_youye c_youye_in c_youye_out'; g('c_diye').className='c_diye c_diye_in'; g('c_t_1').onclick=function(){ g('c_t_1').setAttribute('s4start','on'); s4.start(); g('c_t_1').onclick=null; }; if(g('c_t_1').getAttribute('s4start')!='on'){ s3.start(1200); g('c_t_1').onclick=null; } },'叶子换大叶子'); //旋转 s3.add(1200,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_view2'; g('c_t_1').className='c_t_1 c_t_in c_t_v2 '; g('c_t_2').className='c_t_2 c_t_in c_t_m2'; }); s3.add(1600,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_view3'; g('c_t_1').className='c_t_1 c_t_in c_t_v3'; g('c_t_2').className='c_t_2 c_t_in c_t_m3'; }); s3.add(2000,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_view4'; g('c_t_1').className='c_t_1 c_t_in c_t_v4'; g('c_t_2').className='c_t_2 c_t_in c_t_m4'; }); s3.add(2400,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in'; g('c_t_1').className='c_t_1 c_t_in c_t_m0'; g('c_t_2').className='c_t_2 c_t_in c_t_v0'; }); s3.add(4400,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_view4'; g('c_t_1').className='c_t_1 c_t_in c_t_v4'; g('c_t_2').className='c_t_2 c_t_in c_t_m4'; }); s3.add(4800,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_view3'; g('c_t_1').className='c_t_1 c_t_in c_t_v3'; g('c_t_2').className='c_t_2 c_t_in c_t_m3'; }); s3.add(5200,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_view2'; g('c_t_1').className='c_t_1 c_t_in c_t_v2'; g('c_t_2').className='c_t_2 c_t_in c_t_m2'; }); s3.add(5600,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in'; g('c_t_1').className='c_t_1 c_t_in c_t_v0'; g('c_t_2').className='c_t_2 c_t_in c_t_m0'; g('c_t_1').onclick=function(){ g('c_t_1').setAttribute('s4start','on'); s4.start(); g('c_t_1').onclick=null; }; }); s3.add(8000,function(){ if(g('c_t_1').getAttribute('s4start')!='on'){ s3.start(1200); } }); s4.add(100,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_v1'; g('c_zongzirou2').className='c_zongzirou2 c_zongzirou2_v1'; g('c_t_3').className='c_t_3 c_t_in c_t_t1'; g('c_t_1').className='c_t_1 c_t_in c_t_tx1'; }); s4.add(600,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_v2'; g('c_zongzirou2').className='c_zongzirou2 c_zongzirou2_v2'; g('c_t_3').className='c_t_3 c_t_in c_t_t2'; g('c_t_1').className='c_t_1 c_t_in c_t_tx2'; }); s4.add(1100,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_v3'; g('c_zongzirou2').className='c_zongzirou2 c_zongzirou2_v3'; g('c_t_3').className='c_t_3 c_t_in c_t_t3'; g('c_t_1').className='c_t_1 c_t_in c_t_tx3'; }); s4.add(1600,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_v4'; g('c_zongzirou2').className='c_zongzirou2 c_zongzirou2_v4'; g('c_t_3').className='c_t_3 c_t_in c_t_t4'; g('c_t_1').className='c_t_1 c_t_in c_t_tx4'; }); s4.add(2600,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_v3'; g('c_zongzirou2').className='c_zongzirou2 c_zongzirou2_v3'; g('c_t_3').className='c_t_3 c_t_in c_t_t3'; g('c_t_1').className='c_t_1 c_t_in c_t_tx3'; }); s4.add(3100,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_v2'; g('c_zongzirou2').className='c_zongzirou2 c_zongzirou2_v2'; g('c_t_3').className='c_t_3 c_t_in c_t_t2'; g('c_t_1').className='c_t_1 c_t_in c_t_tx2'; }); s4.add(3600,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in c_zongzirou_v1'; g('c_zongzirou2').className='c_zongzirou2 c_zongzirou2_v1'; g('c_t_3').className='c_t_3 c_t_in c_t_t1'; g('c_t_1').className='c_t_1 c_t_in c_t_tx1'; }); s4.add(4100,function(){ g('c_zongzirou').className='c_zongzirou c_zongzirou_in'; g('c_zongzirou2').className='c_zongzirou2'; g('c_t_3').className='c_t_3'; g('c_t_1').className='c_t_1 c_t_in'; }); s4.add(4500,function(){ g('c_t_1').setAttribute('s4start','off'); s3.start(); }); //图片加载器 var imgs=['img/zzr_2.png','img/zzr_3.png','img/zzr_4.png']; var imgs_onload=function(){ imgs.pop(); if(imgs.length === 0) { s.start(); } }; for(var j in imgs){ var img=new Image(); img.onload=imgs_onload; img.src=imgs[j]; } </ script > </ body > </ html > |