第238练的最终效果如下:
HTML:
<!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>第238练</title><link rel=”stylesheet” href=”https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css” integrity=”sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w==” crossorigin=”anonymous” /><link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css” rel=”stylesheet” integrity=”sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6″ crossorigin=”anonymous”><link rel=”stylesheet” href=”index.css”></head><body><div class=”preloader”><img src=”preloader.gif” alt=”preloader”></div><Header><video class=”background-video” muted autoplay loop src=”background-video.mp4″></video><h1>第238练开启</h1><button class=”btn btn-secondary”><i class=”fa fa-pause” aria-hidden=”true”></i></button></Header><script src=”index.js”></script></body></html>
CSS:
body {margin: 0;padding: 0;font-family: sans-serif;}h1 {font-size: 2.5rem;color: white;letter-spacing: 0.277em;font-weight: 300;}.background-video {position: absolute;top: 0;left: 0;z-index: -1;width: 100%;height: 100%;object-fit: cover;filter: brightness(30%);}header {min-height: 100vh;display: grid;place-items: center;}.preloader {position: fixed;top: 0;left: 0;right: 0;bottom: 0;background: white;display: grid;justify-content: center;align-items: center;z-index: 999;transition: 0.1s linear;}
JS:
const btn = document.querySelector(“.btn”);const video = document.querySelector(“.background-video”);const fa = document.querySelector(“.fa”);const preloader = document.querySelector(“.preloader”);btn.addEventListener(“click”, () => {if (btn.classList.contains(“pause”)) {btn.classList.remove(“pause”);video.play();fa.classList.add(“fa-pause”);fa.classList.remove(“fa-play”);} else {btn.classList.add(“pause”);video.pause();fa.classList.remove(“fa-pause”);fa.classList.add(“fa-play”);}});window.addEventListener(“load”, () => {preloader.style.zIndex = “-999”;});
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...