原生JS实现移动端上下滑动一次一屏(仿抖音)

功能如下:

  • 头部: 附近、关注、推荐选项卡的切换
  • 左右滑动功能、头部选项卡跟随动画
  • 上下滑动划动一屏,滑动超过头部刷新
  • 双击选项卡回到顶部

原生JS实现移动端上下滑动一次一屏(仿抖音)_第1张图片
上代码:

DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Documenttitle>
    <style>
        * {
     
            margin: 0;
            padding: 0;
            -moz-user-select: none;
            /*火狐*/
            -webkit-user-select: none;
            /*webkit浏览器*/
            -ms-user-select: none;
            /*IE10*/
            -khtml-user-select: none;
            /*早期浏览器*/
            user-select: none;
        }

        #box {
     
            width: 350px;
            height: 500px;
            margin: 30px auto;
            border-radius: 5px;
            box-shadow: 0px 0px 27px -3px red;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            -ms-border-radius: 5px;
            -o-border-radius: 5px;
            overflow: hidden;
            position: relative;
            background-color: #ccc;
        }

        .childbox {
     
            width: 300%;
            height: 100%;
            display: flex;
            position: absolute;
            top: 0;
            left: 0;
        }

        .childbox>div {
     
            flex: 1;
            height: 100%;
        }

        .child1 {
     
            background-color: salmon;
        }

        .child2 {
     
            background-color: greenyellow;
        }

        .child3 {
     
            background-color: blueviolet;
        }

        .nav_box {
     
            position: absolute;
            width: 100%;
            text-align: center;
            line-height: 50px;
        }

        .nav_box div {
     
            display: inline-block;
            color: #fff;
            margin: 0 5px;
            position: relative;
        }

        .active_nav::before {
     
            content: '';
            position: absolute;
            background-color: #fff;
            left: 2px;
            bottom: 7px;
            width: 27px;
            height: 2px;
        }

        .childbox>div {
     
            position: relative;
        }

        .childbox>div .listview {
     
            width: 100%;
            position: absolute;
        }

        .view_child {
     
            text-align: center;
            line-height: 200px;
            color: #fff;
            font-size: 25px;
        }
    style>
head>

<body>
    <div id="box">
        <div class="childbox">
            <div class="child1">
                <div 

你可能感兴趣的:(javascript,javascript,js,html,css)