JS实现鼠标滚轮横向滚动特效

点击打开视频讲解

<!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>末晨曦吖</title>
</head>
<body>
    <div id="app">
       <div class="content">
            <div class="page">滚动页面1</div>
            <div class="page">滚动页面2</div>
            <div class="page">滚动页面3</div>
       </div>
    </div>
    <script>
       let content = document.querySelector('.content')
       content.addEventListener('wheel',(event) => {
            event.preventDefault();
            content.scrollLeft += event.deltaY
       })
    </script>
</body>
<style scoped>
    body{
        padding: 0;
        margin: 0;
    }
    .content{
        display: flex;
        overflow-x: scroll;
    }
    .page{
        width: 100%;
        height: 100vh;
        flex-shrink: 0;
    }
    .page:nth-child(1){
        background: red;
    }
    .page:nth-child(2){
        background: blue;
    }
    .page:nth-child(3){
        background: yellow;
    }
</style>
</html>


posted @   程序猿咬棒棒糖拽天下  阅读(506)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示