期末的前端开发大作业仿照着BiliBili和参考大佬的开源项目制作了这个网站 虽然很low
仿BiliBili前端网页制作
图片展示
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 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
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>哔哩哔哩 (゜-゜)つロ 干杯~-bilibili</title> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <link rel="stylesheet" href="./css/index.css"> <link rel="stylesheet" href="./css/fa_icon/all.min.css"> </head> <body>
<div class=""> <div class="vidContainer"> <video class="vid" loop autoplay="autoplay" muted="muted" src="img/banner/headbanner.webm" ></video> </div> <div class="navContainer"> <div class="first-nav"> <ul class="f-n"> <li>主站</li> <li>番剧</li> <li>游戏中心</li> <li>直播</li> <li>会员购</li> <li>漫画</li> <li>赛事</li> <li>高考季</li> <li style="font-size: 16px">下载App</li> </ul> </div> <div class="searchInput"> <input type="text" placeholder="亚比囧囧囧~" /> <div class="searchBtn"> <a class="fa fa-search" href=""></a> </div> </div> <div class="userSection"> <div class="user-left"> <div class="touxaing"> <img src="./img/touxiang.jpg" width="36px" height="36px" alt="" /> </div> <a href="">大会员</a> <a href="">消息</a> <a href="">动态</a> <a href="">大会员</a> <a href="">历史</a> <a href="">创作中心</a> </div> <div class="user-right"> <div class="userDetail"> <a href="javascript:;" style="color: white">投稿</a> </div> </div> </div> </div> <div class="biliLogo"> <img src="./img/logo.png" width="168px" alt=""> <span>戳我试试</span> </div> </div> <div class="first-section"> <div class="f-1"> <div class="l-1"> <ul class="l-ul"> <li> <a> <div class="fa fa-home circle" style="background-color: #ff5c7c"></div> <p>首页</p> </a> </li> <li> <a> <div class="fa fa-home circle" style="background-color: #ff5c7c"></div> <p>动态</p> </a> </li> <li> <a> <div class="fa fa-fire-alt circle" style="background-color: #ff716d"></div> <p>热门</p> </a> </li> <li> <a> <div class="fa fa-radiation-alt circle" style="background-color: #6dc781"></div> <p>频道</p> </a> </li> </ul> </div> <span class="line"></span> <div class="l-2"> <a href=""> <span>动画<em>999+</em></span> </a> <a href=""> <span>音乐<em>999+</em></span> </a> <a href=""> <span>舞蹈<em>999+</em></span> </a> <a href=""> <span>知识<em>999+</em></span> </a> <a href=""> <span>生活<em>999+</em></span> </a> <a href=""> <span>时尚<em>999+</em></span> </a> <a href=""> <span>娱乐<em>999+</em></span> </a> <a> <span>放映厅<em>999+</em></span> </a> <a href=""> <span>番剧<em>999+</em></span> </a> <a href=""> <span>国创<em>999+</em></span> </a> <a href=""> <span>游戏<em>999+</em></span> </a> <a href=""> <span>科技<em>999+</em></span> </a> <a href=""> <span>鬼畜<em>999+</em></span> </a> <a href=""> <span>资讯<em>999+</em></span> </a> <a href=""> <span>影视<em>999+</em></span> </a> <a href=""> <span>更多<i class="fa fa-angle-down" style="font-size: 16px"></i></span> </a> </div> <span class="line"></span> <div class="l-3"> <ul class="l-3Nav"> <li> <a href=""> <em class="fab fa-buffer"></em> 专栏 </a> </li> <li> <a href=""> <em class="fa fa-flag"></em> 活动 </a> </li> <li> <a href=""> <em class="fa fa-boxes"></em> 小黑屋 </a> </li> <li> <a href=""> <em class="fa fa-camera"></em> 直播 </a> </li> <li> <a href=""> <em class="fab fa-hire-a-helper"></em> 课堂 </a> </li> <li> <a href=""> <em class="fa fa-music"></em> 音乐PLUS </a> </li> </ul> </div> </div> </div> </div>
<div class="second-section"> <div class="autoShow"> <div class="autoshow-wrapper"> <a class="lubo" href=""> <img src="img/lunbo/lunbo1.avif" /> </a> <a class="lubo" href=""> <img src="./img/lunbo/lunbo2.avif" /> </a> <a class="lubo" href=""> <img src="./img/lunbo/lunbo3.avif" /> </a> <a class="lubo" href=""> <img src="img/lunbo/lunbo4.avif" /> </a> <a class="lubo" href=""> <img src="./img/lunbo/lunbo5.avif" /> </a> </div> <div class="eat"> </div> <button class="prev">❮</button> <button class="next">❯</button> </div>
<div class="tuijian"> <div class="t-1"> <img src="./img/tuijian/tuijian1.avif" /> <div class="imgContent"> <h2>☕️优雅永不过时~♪☕️</h2> <div class="up-Wrapper"> <span class="up">UP</span>CJY_e <p class="uppig">56.3w播放</p> </div> </div> </div> <div class="t-1"> <img src="./img/tuijian/tuijian2.avif" /> <div class="imgContent"> <h2>我的窝囊人生</h2> <div class="up-Wrapper"> <span class="up">UP</span>胡翠翠 <p class="uppig">122.7W播放</p> </div> </div> </div> <div class="t-1"> <img src="./img/tuijian/tuijian3.avif" /> <div class="imgContent"> <h2>可以点一下封面吗</h2> <div class="up-Wrapper"> <span class="up">UP</span>CJY_e <p class="uppig">63.8W播放</p> </div> </div> </div> <div class="t-1"> <img src="./img/tuijian/tuijian4.avif" /> <div class="imgContent"> <h2>我爱你</h2> <div class="up-Wrapper"> <span class="up">UP</span>aboyzy <p class="uppig">94.6W播放</p> </div> </div> </div> <div class="t-1"> <img src="./img/tuijian/tuijian5.avif" /> <div class="imgContent"> <h2>vlog挪威之旅</h2> <div class="up-Wrapper"> <span class="up">UP</span>aboyzy <p class="uppig">94.6W播放</p> </div> </div> </div> <div class="t-1"> <img src="./img/tuijian/tuijian6.avif" /> <div class="imgContent"> <h2>祝你平安</h2> <div class="up-Wrapper"> <span class="up">UP</span>aboyzy <p class="uppig">1314W播放</p> </div> </div> </div>
</div> </div>
<div class="first-report-section"> <div class="f-left-wrapper"> <div class="f-left-header"> <div class="fa fa-paper-plane"></div> <div style="font-size: 20px; margin-right: 20px">推广</div> <div style="font-size: 12px; color: #505050; line-height: 24.8px"> <span class="fa fa-fire" style="color: #f0361b; font-size: 15px; margin-right: 5px"></span> 萌系星探官招募中 </div> </div> <div class="f-left-content"> <div> <a href="https://www.bilibili.com/bangumi/play/ss43622"> <img src="./img/guang/jdgjj.avif" alt="" /> <p>间谍过家家</p> </a> <span class="up" style="color: #99a6c4; margin-top: 15px">番剧</span>日常、搞笑 </div> <div> <a href="https://www.bilibili.com/bangumi/play/ss2688"> <img src="./img/guang/ms5lm.avif" alt="" /> <p>秒速五厘米</p> </a> <span class="up" style="color: #99a6c4; margin-top: 15px">电影</span> 催泪、日常 </div> <div> <a href="https://www.bilibili.com/bangumi/play/ss40028"> <img src="./img/guang/zll.avif" alt="" /> <p>紫罗兰永恒花园</p> </a> <span class="up" style="color: #99a6c4; margin-top: 15px">电影</span> 奇幻、爱情 </div> <div> <a href="https://www.bilibili.com/bangumi/play/ss12548l"> <img src="./img/guang/rzdf.avif" alt="" /> <p>让子弹飞</p> </a> <span class="up" style="color: #99a6c4; margin-top: 15px">电影</span> 励志 </div> <div> <a href=""> <img src="" alt="" /> <p></p> </a> <span class="up" style="color: #99a6c4; margin-top: 15px"></span> </div>
</div> </div> <div class="f-right-wrapper"> <div class="f-right-header"> <h2>观看列表</h2> </div> <div class="f-right-content"> <img src="./img/guang/fenli.avif" style="width: 320px" /> </div> </div> </div>
<div class="reportTitle"> <img src="./img/fenge.jpg" alt="" srcset=""> </div> </body> <script src="./js/index.js"></script> <script src="./js/banner.js"></script> </html>
|
CSS
使用了外部的图标库FA5 这里未进行展示
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 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
| * { margin: 0; padding: 0; }
.vidContainer { width: 100%; display: flex; justify-content: center; overflow: hidden; }
.vid { position: relative; width: 110%; height: 100%; }
.navContainer { position: absolute; display: flex; justify-content: space-between; align-items: center; width: 100%; height: 56px; top: 10px; }
.first-nav { display: flex; height: 36px; min-width: 452px; margin-left: 20px; }
.f-n { display: flex; align-items: center; font-size: 14px; color: #fff; text-shadow: 0 1px 1px rgb(0 0 0 / 30%); }
.f-n li { margin-right: 12px; cursor: pointer; text-align: center; list-style: none; }
.searchInput { display: flex; position: relative; left: -20px; width: 500px; height: 36px; }
.searchInput input { height: 100%; width: 85.99%; outline: none; padding: 0 38px 0 16px; border: 1px solid hsla(0, 0%, 100%, 0); border-radius: 4px 0 0 4px; background-color: #fff; }
.searchBtn { width: 14.11%; height: 100%; border-radius: 0 4px 4px 0; background: #e7e7e7; border: 1px solid hsla(0, 0%, 100%, 0); cursor: pointer; text-align: center; }
.searchBtn a { color: #505050; line-height: 36px; text-align: center; transition: all linear 0.2s; text-decoration: none; }
.searchBtn a:hover { color: #00a1d6; }
.userSection { display: flex; margin-right: 20px; height: 36px; }
.user-left { display: flex; align-items: center; width: 80%; height: 100%; }
.user-left a { font-size: 14px; color: #fff; text-shadow: 0 1px 1px rgb(0 0 0 / 30%); white-space: nowrap; margin-left: 12px; text-decoration: none; } .touxaing { width: 36px; height: 36px; border-radius: 50%; overflow: hidden; margin-right: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; background-color: #fff; }
.user-right { display: flex; } .user-right a { text-decoration: none; }
.userDetail { width: 100px !important; height: 100%; background-color: #fb7299; border-radius: 2px; text-align: center; line-height: 36px; margin-left: 20px; }
.biliLogo { position: absolute; cursor: pointer; top: 56px; left: 154.66px; }
.biliLogo span { position: absolute; width: 80px; height: 40px; line-height: 40px; top: 10px; text-align: center; color: #fff; background: url('../img/logoy.png') no-repeat center center; background-size: 100%; animation: floatmove 2s infinite; transition: all 0.3s; }
.first-section { display: flex; width: 1198px; min-width: 999px; height: 108px; margin: 0 auto; }
.f-1 { display: flex; width: 100%; height: 100%; align-items: center; }
.l-1 { display: flex; height: 68px; }
.l-ul { display: flex; width: 100%; text-align: center; justify-content: space-between; }
.l-ul li { width: 66px; transition: all 0.3s; cursor: pointer; font-size: 14px; list-style: none; width: 50px;
}
.l-ul li p { transition: color linear 0.2s; }
.l-ul li:hover { color: #17a9da; }
.l-ul li a { display: block; height: 54px; }
.l-ul li a div{ line-height: 36px; }
.fa-home, .fa-radiation-alt, .fa-fire-alt { font-size: 20px; color: white; }
.circle { width: 36px; height: 36px; line-height: 36px; text-align: center; border-radius: 50%; margin: 0 auto 4px; }
.l-2 { position: relative; display: flex; height: 68px; top: -5px; flex-wrap: wrap; flex-direction: column; flex: 1; box-sizing: border-box; }
.l-2 a { color: #000; height: 34px; display: flex; box-sizing: border-box; transition: color linear 0.2s; text-decoration: none; }
.l-2 a:hover { color: #17a9da; }
.l-2 span { display: flex; font-size: 14px; line-height: 34px; }
.l-2 em { font-size: 12px; width: 32px; line-height: 15px; height: 15px; display: inline-block; background-color: skyblue; border-radius: 2px; color: #fff; transform: scale(0.85); }
.l-3 { display: flex; flex-direction: column; width: 220px; height: 68px; }
.l-3Nav { display: flex; width: 100%; height: 68px; flex-direction: column; font-size: 14px; flex-wrap: wrap; }
.l-3Nav li { margin-right: 10px; transition: all 0.5s; list-style: none; }
.l-3Nav li:hover a { color: #17a9da; }
.l-3Nav a { line-height: 34px; color: black; transition: color linear 0.2s; text-decoration: none; }
.fa-buffer { color: skyblue; font-size: 20px; }
.fa-flag { color: #f39800; font-size: 18px; }
.fa-boxes { color: #f39800; font-size: 18px; }
.fa-camera { font-size: 20px; color: skyblue; }
.fa-hire-a-helper { font-size: 19px; color: #ffea85; }
.fa-music { font-size: 17px; color: #ffd469; }
.line { display: block; width: 1px; height: 46px; margin: 0 10px; background-color: #e7e7e7; }
.second-section { display: flex; justify-content: space-between; width: 1198px; height: 242px; margin: 0 auto; margin-bottom: 40px; }
.autoShow { position: relative; width: 549px; height: 100%; background-color: pink; opacity: 0; transition: opacity 0.2s; overflow: hidden; }
.autoshow-wrapper img { width: 550px; }
.autoshow-wrapper { width: 550px; position: relative; }
.autoshow-wrapper a { position: absolute; transition: transform 0.2s; }
.eat { position: absolute; display: flex; bottom: 10px; right: 15px; justify-content: space-between; align-items: center; }
.eat span { display: inline-block; width: 6px; height: 6px; border: 2px solid transparent; border-radius: 50%; background-color: #fff; vertical-align: middle; cursor: pointer; transition: all 0.2s; margin-left: 10px; z-index: 10; transition: all linear 0.2s; }
.eat span:hover { transform: scale(1.2); border: 2px solid #fff; background-color: #00a1d6; }
.autoShow .eat span.on { border: 0; border-color: transparent; background-color: transparent; background-image: url(../img/lunbo/pointer.png); background-size: 100% 100%; background-repeat: no-repeat; transform: scale(3); }
button.prev, button.next { position: absolute; top: 50%; width: auto; padding: 16px; margin-top: -22px; color: white; font-weight: bold; font-size: 18px; background-color: rgba(0, 0, 0, 0.5); border: none; cursor: pointer; opacity: 0.5; transition: background-color 0.3s, opacity 0.3s; border-radius: 20%; }
button.prev { left: 0; }
button.next { right: 0; }
button.prev:hover, button.next:hover { background-color: rgba(0, 0, 0, 0.8); opacity: 1; }
.tuijian { width: 674px; display: flex; flex-wrap: wrap; align-items: center; overflow: hidden; }
.tuijian img { width: 206px; height: 116px; }
.t-1 { margin-left: 10px; position: relative; margin-bottom: 10px; overflow: hidden; }
.imgContent { position: absolute; color: #fff; padding: 27px 5px 10px 10px; width: 100%; height: 100%; left: 0; top: 65px; font-weight: 500; text-align: left; font-size: 14px; transition: all 0.2s; white-space: nowrap; cursor: pointer; }
.imgContent h2{ font-size: 100%; vertical-align: baseline; font: inherit; }
.up-Wrapper { width: 100%; height: 80px; position: absolute; bottom: 0; color: #dadad5; font-size: 12px; font-weight: 700; } .up { font-size: 12px; transform: scale(0.8); line-height: 10px; font-weight: 600; text-align: center; width: 17px; height: 10px; border-radius: 3px; color: #dadad5; border: 2px solid #dadad5; } .uppig { color: #dadad5; font-size: 14px; font-weight: 400; } .t-1:hover .imgContent { top: 0; background-color: rgba(0, 0, 0, 0.6); }
.first-report-section { display: flex; width: 1202px; justify-content: space-between; margin: 0 auto; margin-bottom: 20px; }
.f-left-wrapper { width: 864px; height: 100%; overflow: hidden; }
.f-left-header { display: flex; margin-bottom: 20px; }
.fa-paper-plane { font-size: 25px; color: #ffd778; margin-right: 10px; }
.f-left-content { height: 170px; display: flex; overflow: hidden; }
.f-left-content a { text-decoration: none; }
.f-left-content div a img{ transition: transform 0.3s ease; }
.f-left-content div a img:hover{ transform: scale(1.05); }
.f-left-content a p:hover{ color: #7ecdf4; }
.f-left-content img { width: 206px; height: 116px; }
.f-left-content div { margin-right: 10px; font-size: 14px; color: #999999; cursor: pointer; }
.f-left-content div p { margin-top: 10px; color: #212121; }
.f-right-wrapper { width: 321px; height: 100%; }
.f-right-header { position: relative; top: -5px; cursor: pointer; width: 320px; height: 30px; background-color: #f4f4f4; border: 1px solid #e7e7e7; text-align: center; font-size: 12px; line-height: 30px; transition: color 0.2s; margin-bottom: 12px; }
.f-right-header:hover { color: #7ecdf4; }
.f-right-header h2{ font-size: 12px; font: inherit; }
.f-right-content img { width: 320px; height: 184px; }
.reportTitle{ width: 1202px; margin: 0 auto; margin-bottom: 20px; } .reportTitle img{ width: 100%; height: 99px; }
|
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 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
|
const vidContainer = document.querySelector(".vidContainer"); const vid = document.querySelector(".vid");
vidContainer.addEventListener("mouseenter", function (e) { this.x = e.clientX; vid.style.transition = "none"; }); vidContainer.addEventListener("mousemove", function (e) { this._x = e.clientX; const disx = this._x - this.x; const move = 0 - disx / -30; vid.style.transform = "translate(" + move + "px, 0px)"; }); vidContainer.addEventListener("mouseleave", function (e) { vid.style.transition = ".3s "; vid.style.transform = "translate(0,0)"; });
let logo = document.querySelector(".biliLogo"); let srcs = document.querySelector(".vid"); let indexPointer = 0; const lens = 4; logo.onclick = function () { if (indexPointer > lens - 1) { indexPointer = 0; } else if (indexPointer == 0) { srcs.src = "../img/banner/2.webm"; indexPointer++; } else if (indexPointer == 1) { srcs.src = "../img/banner/3.webm"; indexPointer++; } else if (indexPointer == 2) { srcs.src = "../img/banner/4.webm"; indexPointer++; } else if (indexPointer == 3) { srcs.src = "../img/banner/headbanner.webm"; indexPointer++; } };
document.addEventListener('DOMContentLoaded', function() { let items = document.querySelectorAll('.lubo'); let eat = document.querySelector('.eat'); let active = 0; let timer;
for (let i = 0; i < items.length; i++) { let span = document.createElement('span');
if (i === 0) { span.classList.add('on'); } else { items[i].style.transform = 'translate3d(550px, 0, 0)'; }
eat.appendChild(span);
span.addEventListener('click', function() { clearInterval(timer);
if (i !== active) { clearOn(); span.classList.add('on'); }
index = i; changeSlider(i); active = i;
autoShow(); }); }
function changeSlider(newVal) { for (let i = 0; i < items.length; i++) { if (i < newVal) { items[i].style.transform = 'translate3d(-550px, 0, 0)'; } else if (i > newVal) { items[i].style.transform = 'translate3d(550px, 0, 0)'; } else { items[i].style.transform = 'translate3d(0, 0, 0)'; } } }
let index = 0; let spans = document.querySelectorAll('.eat span');
function clearOn() { spans.forEach(span => span.classList.remove('on')); }
function autoShow() { timer = setInterval(function() { if (index >= items.length) { index = 0; } clearOn(); changeSlider(index); spans[index].classList.add('on'); index++; }, 2500); }
autoShow();
setTimeout(function() { document.querySelector('.autoShow').style.opacity = '1'; }, 420);
document.querySelector('.prev').addEventListener('click', function() { clearInterval(timer); index = (index - 1 + items.length) % items.length; clearOn(); changeSlider(index); spans[index].classList.add('on'); autoShow(); });
document.querySelector('.next').addEventListener('click', function() { clearInterval(timer); index = (index + 1) % items.length; clearOn(); changeSlider(index); spans[index].classList.add('on'); autoShow(); }); });
|
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
|
let items = document.querySelectorAll('.lubo');
let tigger = $('.tigger');
let active = 0; let timer ;
for(let i =0 ; i<items.length;i++){ let span = document.createElement('span');
if(i===0){ span.setAttribute('class','on'); }else{ items[i].setAttribute('style','transform:translate3d(550px,0px,0px)'); } tigger.append(span); span.onclick = function(){ clearInterval(timer); if(i!==active){ clearOn(); span.setAttribute('class','on'); } index = i; changeSilder(i); active = i;
autoShow(); } }
function changeSilder(newVal){
for(let i = 0;i<items.length;i++){
if(i < newVal){ items[i].setAttribute('style','transform:translate3d(-550px,0px,0px)'); }else if(i > newVal){ items[i].setAttribute('style','transform:translate3d(550px,0px,0px)'); }else{ items[i].setAttribute('style','transform:translate3d(0px,0px,0px)'); }
}
}
var index = 0; let spans = $('.tigger span');
function clearOn(){ for(let c = 0;c<items.length;c++){ spans[c].className = ''; } } function autoShow(){ timer = setInterval(function(){ if(index > items.length-1){ index=0; } clearOn(); changeSilder(index); spans[index].className='on'; index++;
},2500) }
setTimeout(function(){ $('.autoShow').css('opacity','1');
},420)
|
下载地址 :蓝奏云