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

功能如下:

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

在这里插入图片描述
上代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <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 
  • 10
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值