大阔
发布于 2021-11-08 / 82 阅读 / 0 评论 / 0 点赞

使用相对定位复现虎嗅网图片滚动特效

使用相对定位复现虎嗅网图片滚动特效

前言

在逛虎嗅网的时候发现它使用的滚动图片特效很好看,想尝试复现一下

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .box{
        width: 800px;
        position: relative;
    }

    .box .img{
        position:fixed;
        height: 500px;
        width: 800px;
    }

    .box > p{
        position:absolute;
        top: 500px;
        margin-top: 0px;
        background-color: #5dbe8a;
        color: white;
    }
</style>

<body>
    <div class="box" id="box">
    <img src="img/1.jpg" class="img">
    <p>...</p>

    </div>
</body>

</html>

主要是使用相对定位将图片固定在了文章下面,滚动时可以实现图片消失的效果,非常简单,推荐学习一下。

实现效果


评论