HTML+CSS简单实现页面滚动

HTML:
 

<!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="style.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.css" rel="stylesheet">
</head>
<body>
    <section id="page-1" class="page">
        <h1>第一页</h1>
        <p>内容....</p>
        <div>
            <a href="#page-2" class="btn">
                下一页
                <i class="fas fa-arrow-circle-down"></i>
            </a>
        </div>
    </section>
    <section id="page-2" class="page">
        <h1>第二页</h1>
        <p>内容....</p>
        <div>
            <a href="#page-1" class="btn btn-dark">
                上一页
                <i class="fas fa-arrow-circle-up"></i>
            </a>
            <a href="#page-3" class="btn">
                下一页
                <i class="fas fa-arrow-circle-down"></i>
            </a>
        </div>
    </section>
    <section id="page-3" class="page">
        <h1>第三页</h1>
        <p>内容....</p>
        <div>
            <a href="#page-2" class="btn btn-dark">
                上一页
                <i class="fas fa-arrow-circle-up"></i>
            </a>
            <a href="#page-4" class="btn">
                下一页
                <i class="fas fa-arrow-circle-down"></i>
            </a>
        </div>
    </section>
    <section id="page-4" class="page">
        <h1>第四页</h1>
        <p>内容....</p>
        <div>
            <a href="#page-3" class="btn btn-dark">
                上一页
                <i class="fas fa-arrow-circle-up"></i>
            </a>
        </div>
    </section>
</body>
</html>

CSS:

:root{
    --page-1-color:steelblue;
    --page-2-color:tan;
    --page-3-color:teal;
    --page-4-color:tomato;
    ---animate-speed: 1s;
}
html{
    scroll-behavior: smooth;
}
body{
    line-height: 1.4;
    margin: 0;
    padding: 0;
    overflow: hidden;
    color: #fff;
}
/* page color */
#page-1{background: var(--page-1-color);}
#page-2{background: var(--page-2-color);}
#page-3{background: var(--page-3-color);}
#page-4{background: var(--page-4-color);}
/*  */
.page{
    display: flex;
    flex-direction: column;
    height: 100vh;
    justify-content: center;
    align-items: center;
    text-align: center;
}
/*  */
section h1{
    font-size: 4rem;
    line-height: 1.2;
    margin: 1rem;
}
section p{
    font-size: 1.3rem;
}
section .btn{
    display: inline-block;
    padding: 1rem 1.5rem;
    border: none;
    text-decoration: none;
    margin-top: 1rem;
    font-size: 1.1rem;
    background-color: #fff;
    transition: all 0.5s ease-in;
}
section .btn:hover{
    color: white;
    background: #000;
}
/* 动画 */
#page-1 h1{
    transform: translateY(-1200px);
    animation: heading var(---animate-speed)
    forwards ease-in 1s;
}
#page-1 p{
    transform: translateX(-1600px);
    animation: text var(---animate-speed) forwards
    ease-in 2s;
}
@keyframes heading {
    to{
        transform: translateY(0);
    }
}
@keyframes text {
    to{
        transform: translateX(0);
    }
}

效果图:

 参考自B站教程:06-CSS进阶实战-06_01_03页面动画制作_哔哩哔哩_bilibili

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值