CSS 3.0扭曲實現的滾動傾斜背景特效

今天給大家分享一個用CSS 3.0扭曲實現的滾動傾斜背景特效,效果如下: 

以下是代碼實現,歡迎大家複製粘貼和收藏。

<!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>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章