CSS 3.0扭曲实现的滚动倾斜背景特效

2020-11-26 11:25:57 浏览数 (1)

今天给大家分享一个用CSS 3.0扭曲实现的滚动倾斜背景特效,效果如下:

以下是代码实现,欢迎大家复制粘贴和收藏。

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS 3.0扭曲实现的滚动倾斜背景特效</title>
    <style>
        * {
            font-family: '微软雅黑', sans-serif;
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            height: 200vh;
            background: #fff;
        }

        section {
            position: absolute;
            width: 100%;
            height: 100%;
            background: url(https://img.lanrentuku.com/img/allimg/1707/14988864745279.jpg), linear-gradient(230deg, #f533d4, #2461bb);
            background-size: cover;
            background-blend-mode: luminosity;
        }

        section .skewed {
            position: absolute;
            bottom: -100%;
            left: 0;
            width: 100%;
            height: 100%;
            background: #fff;
            transform: skewY(-10deg);
            transform-origin: top left;
        }
    </style>
</head>

<body>
    <section>
        <span class="skewed"></span>
    </section>

    <script>
        let skewed = document.querySelector('.skewed')
        window.addEventListener('scroll', function () {
            let value = -10   window.scrollY / 60
            skewed.style.transform = `skewY(${value}deg)`
        })
    </script>
</body>

</html>

0 人点赞