原生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-c.........完整代码请登录后点击上方下载按钮下载查看

网友评论0