加载效果
代码
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>加载效果</title><link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"><script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"crossorigin="anonymous"></script><style>* {margin: 0;padding: 0;}body {background: #2980b9;}.loading {height: 40px;position: absolute;top: 50%;left: 50%;display: flex;transform: translate(-50%, -50%);align-items: center;}.object {width: 6px;height: 40px;background: white;margin: 0 3px;border-radius: 10px;animation: loading 0.8s infinite;animation-play-state: paused;}.xyBtn {position: absolute;top: 60%;left: 50%;transform: translate(-40%, -50%);}.object:nth-child(2) {animation-delay: 0.1s;}.object:nth-child(3) {animation-delay: 0.2s;}.object:nth-child(4) {animation-delay: 0.3s;}.object:nth-child(5) {animation-delay: 0.4s;}.object:nth-child(6) {animation-delay: 0.5s;}.object:nth-child(7) {animation-delay: 0.6s;}.object:nth-child(8) {animation-delay: 0.7s;}@keyframes loading {0% {height: 0;}50% {height: 40px;}100% {height: 0;}}.animate {animation-play-state: running;}.paused {animation-play-state: paused;}</style>
</head><body><div class="loading"><div class="object"></div><div class="object"></div><div class="object"></div><div class="object"></div><div class="object"></div><div class="object"></div><div class="object"></div><div class="object"></div></div><button type="button" class="btn btn-info xyBtn" id="toggleButton">开始动画</button><script>var toggleButton = document.getElementById("toggleButton");var objectElements = document.getElementsByClassName("object");var animationState = false;toggleButton.addEventListener("click", function () {animationState = !animationState;if (animationState) {for (var i = 0; i < objectElements.length; i++) {objectElements[i].classList.add("animate");objectElements[i].classList.remove("paused");}toggleButton.textContent = "暂停动画";} else {for (var i = 0; i < objectElements.length; i++) {objectElements[i].classList.add("paused");objectElements[i].classList.remove("animate");}toggleButton.textContent = "开始动画";}});</script>
</body></html>
创意视频球特效
代码
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>创意视频球特效</title><style>* {margin: 0;padding: 0;}body {overflow: hidden;}section {position: absolute;top: -100px;left: -100px;right: -100px;bottom: -100px;display: flex;justify-content: center;align-items: center;}section video {position: absolute;top: 0;left: 0;width: 100%;height: 100%;object-fit: cover;filter: blur(35px);}section .sphere {position: relative;width: 600px;height: 600px;border-radius: 50%;z-index: 10;}section .sphere::before {content: "";position: absolute;top: 0;left: 0;width: 100%;height: 100%;z-index: 100;border-radius: 50%;box-shadow: inset 0 100px 100px rgba(255, 255, 255, 0.5),inset 0 -100px 100px rgba(0, 0, 0, 1),inset 0 0 100px rgba(0, 0, 0, 1);}section .sphere::after {content: "";position: absolute;top: 550px;left: -50px;width: 700px;height: 100px;z-index: -1;border-radius: 50%;background: black;background: radial-gradient(black, transparent, transparent);}section .sphere video {width: 100%;height: 100%;position: absolute;top: 0;left: 0;object-fit: cover;border-radius: 50%;filter: blur(0);}section .controls {position: absolute;bottom: 100px;left: 50%;transform: translateX(-50%);display: flex;align-items: center;}section .controls button {background: none;border: none;outline: none;cursor: pointer;color: white;font-size: 20px;margin-right: 10px;font-family: 'Times New Roman', Times, serif;}section .controls input[type="range"] {width: 800px;margin-right: 10px;}section .controls span {color: white;font-size: 18px;font-family: 'Times New Roman', Times, serif;}</style>
</head><body><section><video id="backgroundVideo" src="../Videos/1-“挑 战 B 站 画 质 上 限”-4K 超清-AVC.mp4"></video><div class="sphere"><video id="sphereVideo" src="../Videos/1-“挑 战 B 站 画 质 上 限”-4K 超清-AVC.mp4"></video></div><div class="controls"><button id="playPauseButton">播放</button><input type="range" id="progressBar" min="0" step="0.001"><span id="currentTime">00:00</span> <span>/</span> <span id="duration">00:00</span></div></section><script>document.addEventListener("DOMContentLoaded", function () {var backgroundVideo = document.getElementById("backgroundVideo"); var sphereVideo = document.getElementById("sphereVideo"); var playPauseButton = document.getElementById("playPauseButton"); var progressBar = document.getElementById("progressBar"); var currentTime = document.getElementById("currentTime"); var duration = document.getElementById("duration"); backgroundVideo.pause();sphereVideo.pause();progressBar.value = 0;playPauseButton.addEventListener("click", function () {if (backgroundVideo.paused) {backgroundVideo.play();sphereVideo.play();playPauseButton.textContent = "暂停"; } else {backgroundVideo.pause();sphereVideo.pause();playPauseButton.textContent = "播放"; }});backgroundVideo.addEventListener("timeupdate", function () {var progress = (backgroundVideo.currentTime / backgroundVideo.duration) * 100;progressBar.value = progress; currentTime.textContent = formatTime(backgroundVideo.currentTime); });progressBar.addEventListener("input", function () {var progressTime = (progressBar.value / 100) * backgroundVideo.duration;backgroundVideo.currentTime = progressTime;sphereVideo.currentTime = progressTime;currentTime.textContent = formatTime(progressTime); });function formatTime(time) {var minutes = Math.floor(time / 60); var seconds = Math.floor(time % 60); return (minutes < 10 ? "0" : "") + minutes + ":" + (seconds < 10 ? "0" : "") + seconds;}backgroundVideo.addEventListener("loadedmetadata", function () {duration.textContent = formatTime(backgroundVideo.duration); });backgroundVideo.addEventListener("ended", function () {playPauseButton.textContent = "播放"; progressBar.value = 0; currentTime.textContent = "00:00"; });});</script>
</body></html>