原生js+css单文件html实现模仿抖音短视频app海外版TikTok ui交互效果代码
代码语言:html
所属分类:布局界面
代码描述:原生js+css单文件html实现模仿抖音短视频app海外版TikTok ui交互效果代码,可以上下滑动切换视频、可以查看评论,底部tab选项卡可点击。
代码标签: 原生 js css 单文件 html 模仿 抖音 短视频 app 海外版 TikTok ui 交互
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <title>TikTok Clone - Single File</title> <style> /* ========================================= CSS RESET & VARIABLES ========================================= */ :root { --tik-black: #000000; --tik-ws: #121212; /* Workspace/Dark BG */ --tik-gray: #888888; --tik-light-gray: #e2e2e2; --tik-white: #ffffff; --tik-cyan: #69c9d0; --tik-magenta: #ee1d52; --tik-primary: #fe2c55; --tik-border: #2f2f2f; --font-stack: 'Proxima Nova', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; --bottom-nav-height: 50px; --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px); } *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; } body { font-family: var(--font-stack); background-color: var(--tik-black); color: var(--tik-white); overflow: hidden; /* Prevent body scroll, handle in app-container */ height: 100vh; width: 100vw; display: flex; justify-content: center; align-items: center; } /* ========================================= APP CONTAINER & LAYOUT ========================================= */ #app { position: relative; width: 100%; height: 100%; max-width: 450px; /* Constrain on desktop */ background-color: var(--tik-black); overflow: hidden; box-shadow: 0 0 20px rgba(0,0,0,0.5); } /* Views (SPA Routing) */ .view { position: absolute; top: 0; left: 0; width: 100%; height: calc(100% - var(--bottom-nav-height) - var(--safe-area-inset-bottom)); display: none; flex-direction: column; background-color: var(--tik-black); } .view.active { display: flex; } /* ========================================= TOP NAVIGATION (Feed) ========================================= */ .top-nav { position: absolute; top: 10px; left: 0; width: 100%; z-index: 100; display: flex; justify-content: center; align-items: center; gap: 20px; background: transparent; padding-top: env(safe-area-inset-top, 10px); } .top-nav span { font-size: 16px; font-weight: 600; color: var(--tik-light-gray); opacity: 0.7; cursor: pointer; position: relative; text-shadow: 0 1px 3px rgba(0,0,0,0.5); } .top-nav span.active { color: var(--tik-white); opacity: 1; } .top-nav span.active::after { content: ''; position: absolute; bottom: -5px; left: 50%; transform: translateX(-50%); width: 20px; height: 2px; background-color: var(--tik-white); border-radius: 2px; } .live-icon { position: absolute; left: 15px; top: env(safe-area-inset-top, 15px); } .search-icon { position: absolute; right: 15px; top: env(safe-area-inset-top, 15px); } /* SVG Icon Utility */ .icon { width: 24px; height: 24px; fill: white; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5)); } /* ========================================= VIDEO FEED & SCROLL SNAP ========================================= */ #home-view { background-color: var(--tik-black); } .video-feed { width: 100%; height: 100%; overflow-y: scroll; scroll-snap-type: y mandatory; scrollbar-width: none; /* Firefox */ } .video-feed::-webkit-scrollbar { display: none; /* Chrome/Safari */ } .video-container { position: relative; width: 100%; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; background-color: #1a1a1a; overflow: hidden; } .video-player { width: 100%; height: 100%; object-fit: cover; display: block; } /* Video Overlay UI */ .video-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; /* Let clicks pass through to video for double tap */ z-index: 10; } /* Sidebar Actions (Right) */ .sidebar { position: absolute; right: 10px; bottom: 80px; display: flex; flex-direction: column; align-items: center; gap: 20px; pointer-events: auto; } .sidebar-item { display: flex; flex-direction: column; align-items: center; position: relative; } .avatar-container { width: 48px; height: 48px; border-radius: 50%; background: white; padding: 1px; position: relative; margin-bottom: 10px; } .avatar { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; } .follow-plus { position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%); width: 20px; height: 20px; background-color: var(--tik-primary); border-radius: 50%; display: flex; justify-content: center; align-items: center; color: white; font-size: 16px; font-weight: bold; transition: transform 0.2s; } .action-btn { width: 40px; height: 40px; display: flex; justify-content: center; align-items: center; transition: transform 0.1s; cursor: pointer; } .action-btn:active { transform: scale(0.8); } .action-text { font-size: 12px; font-weight: 600; margin-top: 4px; text-shadow: 0 1px 2px rgba(0,0,0,0.6); } /* Heart Animation Class */ .liked .icon-heart { fill: var(--tik-primary); animation: heartBeat 0.4s forwards; } @keyframes heartBeat { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } } /* Bottom Info (Left) */ .bottom-info { position: absolute; bottom: 20px; left: 10px; width: 70%; pointer-events: auto; z-index: 11; } .author-name { font-size: 17px; font-weight: 700; margin-bottom: 8px; text-shadow: 0 1px 2px rgba(0,0,0,0.8); cursor: pointer; } .video-description { font-size: 14px; line-height: 1.3; margin-bottom: 10px; text-shadow: 0 1px 1px rgba(0,0,0,0.8); } .hashtag { font-weight: 700; margin-right: 5px; } .music-ticker { display: flex; align-items: center; font-size: 14px; } .music-icon { margin-right: 10px; width: 14px; height: 14px; } .marquee-container { width: 150px; overflow: hidden; white-space: nowrap; } .marquee-text { display: inline-block; padding-left: 100%; animation: marquee 10s linear infinite; } @keyframes marquee { 0% { transform: translate(0, 0); } 100% { transform: translate(-100%, 0); } } /* Spinning Disc */ .disc-container { position: absolute; right: 10px; bottom: 20px; width: 50px; height: 50px; pointer-events: auto; } .disc-bg { width: 100%; height: 100%; background: linear-gradient(#222, #111); border-radius: 50%; display: flex; justify-content: center; align-items: center; border: 8px solid #111; animation: spin 5s linear infinite; box-shadow: 0 0 5px rgba(0,0,0,0.5); } .disc-bg.paused { animation-play-state: paused; } .disc-art { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; } @keyframes spin { 100% { transform: rotate(360deg); } } .music-notes { position: absolute; bottom: 10px; right: 10px; } .note { position: absolute; width: 10px; height: 10px; opacity: 0; fill: var(--tik-gray); } .note1 { animation: floatNote 2s linear infinite; bottom: 40px; right: 10px; } .note2 { animation: floatNote 2s linear infinite 0.5s; bottom: 40px; right: 20px; font-size: 12px;} @keyframes floatNote { 0% { opacity: 0; transform: translateY(0) rotate(0deg) scale(0.5); } 20% { opacity: 0.8; } 100% { opacity: 0; transform: translateY(-60px) rotate(45deg) scale(1); } } /* Play/Pause Indicator */ .play-pause-indicator { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 80px; opacity: 0; transition: opacity 0.2s, transform 0.2s; color: rgba(255,255,255,0.7); pointer-events: none; z-index: 5; } /* ========================================= DOUBLE TAP HEART ANIMATION ========================================= */ .floating-heart { position: absolute; width: 80px; height: 80px; fill: var(--tik-primary); transform: translate(-50%, -50%) scale(0); opacity: 1; pointer-events: none; z-index: 100; animation: floatHeartAnim 0.8s ease-out forwards; filter: drop-shadow(0 0 5px rgba(0,0,0,0.5)); } @keyframes floatHear.........完整代码请登录后点击上方下载按钮下载查看
网友评论0