RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1237687
Accepted
Проста Miha
Проста Miha
Asked:2022-01-30 05:14:46 +0000 UTC2022-01-30 05:14:46 +0000 UTC 2022-01-30 05:14:46 +0000 UTC

如何制作幻灯片,以便当您单击所有图片时左右移动?

  • 772

如何实现,点击L时,所有图片都向左移动,点击R时,反之亦然?

const hamburger_menu = document.querySelector(".hamburger-menu");
        const container = document.querySelector(".container");
        const bottom = document.querySelector(".bottom");

        hamburger_menu.addEventListener("click", () => {
            container.classList.toggle("active");
            bottom.classList.toggle("show");
        });

        const arrow_right = document.querySelector(".right");
        const main = document.querySelector(".main");
        const shadow_one = document.querySelector(".one");
        const shadow_two = document.querySelector(".two");
        arrow_right.addEventListener("click", () => {
            shadow_one.style.transform = "perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5)";
            shadow_one.style.left = "350px";
            shadow_one.style.zIndex = "3";

            shadow_two.style.transform = "perspective(1300px) rotateY(20deg) translateZ(215px) scale(0.5)";
            shadow_two.style.left = "100px";
            shadow_two.style.zIndex = "2";

            main.style.transform = "perspective(1300px) rotateY(20deg) translateZ(120px) scale(0.5)";
            main.style.left = "-25px";
            main.style.zIndex = "1";
        });
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;600;700;800;900&display=swap');
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
            font-family: 'Orbitron', sans-serif;
        }

        img{
            position: absolute;
            width: 600px;
            height: auto;
            left: 50%;
            transform: translateX(-50%);
            z-index: 1;
        }

        .container{
            min-height: 100vh;
            width: 100%;
            background-color: #485461;
            background-image: linear-gradient(135deg, #485461 0%, #28313b 74%);
            overflow-x: hidden;
            transform-style: preserve-3d;
        }

        .navbar{
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            z-index: 10;
        }

        .hamburger-menu{
            height: 4rem;
            width: 2rem;
            cursor: pointer;
            display: flex;
            float: right;
            margin-right: 150px;
            align-items: center;
            justify-content: flex-end;
        }

        .bar{
            width: 2rem;
            height: 1.5px;
            border-radius: 2px;
            background-color: #eee;
            transition: 0.5s;
            position: relative;
        }

        .bar:before,
        .bar:after {
            content: "";
            position: absolute;
            width: inherit;
            height: inherit;
            background-color: #eee;
            transition: 0.5s;
        }

        .bar:before {
            transform: translateY(-9px);
        }

        .bar:after {
            transform: translateY(9px);
        }

        .main{
            position: relative;
            width: 100%;
            left: 0;
            z-index: 5;
            overflow: hidden;
            transform-origin: left;
            transform-style: preserve-3d;
            transition: 0.5s;
        }

        header{
            min-height: 100vh;
            width: 100%;
            background-color: grey;
        }

        .overlay{
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .container.active .bar{
            transform: rotate(360deg);
            background-color: transparent;
        }

        .container.active .bar:before{
            transform: translateY(0) rotate(45deg);
        }

        .container.active .bar:after{
            transform: translateY(0) rotate(-45deg);
        }

        .container.active .main{
            animation: main-animation 0.5s ease;
            left: 350px;
            cursor: pointer;
            transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
        }

        @keyframes main-animation{
            from{
                transform: translate(0);
            }

            to{
                transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
            }
        }

        .links{
            position: absolute;
            width: 20%;
            right: 0;
            top: 0;
            height: 100vh;
            z-index: 2;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        ul{
            list-style: none;
        }

        .links a{
            text-decoration: none;
            color: #fcec0c;
            padding: 0.7rem 0;
            display: inline-block;
            font-size: 1rem;
            font-weight: 300;
            text-transform: uppercase;
            letter-spacing: 1px;
            transition: 0.3s;
            opacity: 0;
            transform: translateY(10px);
            animation: hide 0.5s forwards ease;
        }

        .links a:hover{
            color: #978d01;
        }

        .container.active .links a{
            animation: appear 0.5s forwards ease var(--i);
        }

        @keyframes appear{
            from{
                opacity: 0;
                transform: translateY(10px);
            }
            to{
                opacity: 1;
                transform: translateY(0px);
            }
        }

        @keyframes hide{
            from{
                opacity: 1;
                transform: translateY(0px);
            }
            to{
                opacity: 0;
                transform: translateY(10px);
            }
        }

        .shadow{
            position: absolute;
            width: 100%;
            height: 100vh;
            top: 0;
            left: 0;
            transform-style: preserve-3d;
            transform-origin: left;
            transition: 0.5s;
            background-color: white;
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }

        .shadow.one{
            z-index: -1;
      background-color: red; 
     }
            

        .shadow.two{
            z-index: -2;
            background-color: blue;
        }

        .container.active .shadow.one{
            animation: shadow-one 0.6s ease-out;
            left: 100px;
            transform: perspective(1300px) rotateY(20deg) translateZ(215px) scale(0.5);
        }

        @keyframes shadow-one{
            0%{
                transform: translate(0);
            }

            5%{
                transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
            }

            100%{
                transform: perspective(1300px) rotateY(20deg) translateZ(215px) scale(0.5);
            }
        }

        .container.active .shadow.two{
            animation: shadow-two 0.6s ease-out;
            left: -25px;
            transform: perspective(1300px) rotateY(20deg) translateZ(120px) scale(0.5);
        }

        @keyframes shadow-two{
            0%{
                transform: translate(0);
            }

            20%{
                transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
            }

            100%{
                transform: perspective(1300px) rotateY(20deg) translateZ(120px) scale(0.5);
            }
        }

        .container.active .main:hover + .shadow.one{
            transform: perspective(1300px) rotateY(20deg) translateZ(230px) scale(0.5);
        }

        .container.active .main:hover{
            transform: perspective(1300px) rotateY(20deg) translateZ(340px) scale(0.5);
        }

        .bottom{
            position: relative;
            width: 100%;
            height: 150px;
            display: none;
        }

        .show{
            display: flex;
            justify-content: center;
            align-items: center;
            top: -125px;
        }

        .arrow{
            font-size: 64px;
            margin: 0 200px;
            cursor: pointer;
            z-index: 10;
            border-radius: 50%;
            color: #fcec0c;
        }

        .arrow:hover .far{
            color: #978d01;
        }
<img src="Image/header.png" alt="">
    <div class="container">
        <div class="navbar">
            <div class="hamburger-menu">
                <div class="bar"></div>
            </div>
        </div>

        <div class="main-container">
            <div class="main">
                <header>
                    <div class="overlay"></div>
                </header>
            </div>

            <div class="shadow one"></div>
            <div class="shadow two"></div>

            <div class="bottom">
                <div class="arrow left">L</div>
                <div class="arrow right">R</div>
            </div>
        </div>

        <div class="links">
            <ul>
                <li>
                    <a href="#" style="--i: 0.05s;">Home</a>
                </li>
                <li>
                    <a href="#" style="--i: 0.1s;">Services</a>
                </li>
                <li>
                    <a href="#" style="--i: 0.15s;">Portfolio</a>
                </li>
                <li>
                    <a href="#" style="--i: 0.2s;">Testimonials</a>
                </li>
            </ul>
        </div>
    </div>

javascript
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Denis640Kb
    2022-01-30T18:06:50Z2022-01-30T18:06:50Z

    如果你真的不想使用幻灯片库,那么你可以这样实现(添加更多注释以供理解):

        const hamburger_menu = document.querySelector(".hamburger-menu");
        const container = document.querySelector(".container");
        const bottom = document.querySelector(".bottom");
    
        hamburger_menu.addEventListener("click", () => {
            container.classList.toggle("active");
            bottom.classList.toggle("show");
        });
    
        let arrow_right = document.querySelector(".right"); // Правая кнопка
        let arrow_left = document.querySelector(".left"); // Левая кнопка
        const main = document.querySelector(".main");
        const shadow_one = document.querySelector(".one");
        const shadow_two = document.querySelector(".two");
        let moveR = [[shadow_one,shadow_two,main],[shadow_two,main,shadow_one],[main,shadow_one,shadow_two]]; // Массив блоков для удобства смены
    
        arrow_right.addEventListener("click", () => { // для правой кнопки
            let trig = +arrow_right.dataset.val+1; // Получаем триггер из кнопки
            if(trig >= moveR.length){ // Если больше чем количество в массиве, то ставим 0
                trig = 0;
            }
            move(trig); // Выполняем функцию с движением направо
            arrow_right.dataset.val=trig; // проставляем новое знаечние дата параметра в кнопку
        });
    
        arrow_left.addEventListener("click", () => { // для левой кнопки
            let trig = +arrow_right.dataset.val-1; // Получаем триггер из той же самой кнопки
            if(trig < 0){ // Если меньше нуля, то ставим количество элементво массива -1, так как ключи начинаются с 0.
                trig = moveR.length-1;
            }
            move(trig); // Выполняем функцию с движением
            arrow_right.dataset.val=trig; // проставляем новое знаечние дата параметра в кнопку
        });
    
        function move(trig) { // Выносим отдельно в универсальную функцю для удобства
            let z=moveR[trig]; // Берём нужный массив
            z[0].style.transform = "perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5)";
            z[0].style.left = "350px";
            z[0].style.zIndex = "3";
    
            z[1].style.transform = "perspective(1300px) rotateY(20deg) translateZ(215px) scale(0.5)";
            z[1].style.left = "100px";
            z[1].style.zIndex = "2";
    
            z[2].style.transform = "perspective(1300px) rotateY(20deg) translateZ(120px) scale(0.5)";
            z[2].style.left = "-25px";
            z[2].style.zIndex = "1";
        }
        @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;600;700;800;900&display=swap');
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
            font-family: 'Orbitron', sans-serif;
        }
    
        img{
            position: absolute;
            width: 600px;
            height: auto;
            left: 50%;
            transform: translateX(-50%);
            z-index: 1;
        }
    
        .container{
            min-height: 100vh;
            width: 100%;
            background-color: #485461;
            background-image: linear-gradient(135deg, #485461 0%, #28313b 74%);
            overflow-x: hidden;
            transform-style: preserve-3d;
        }
    
        .navbar{
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            z-index: 10;
        }
    
        .hamburger-menu{
            height: 4rem;
            width: 2rem;
            cursor: pointer;
            display: flex;
            float: right;
            margin-right: 150px;
            align-items: center;
            justify-content: flex-end;
        }
    
        .bar{
            width: 2rem;
            height: 1.5px;
            border-radius: 2px;
            background-color: #eee;
            transition: 0.5s;
            position: relative;
        }
    
        .bar:before,
        .bar:after {
            content: "";
            position: absolute;
            width: inherit;
            height: inherit;
            background-color: #eee;
            transition: 0.5s;
        }
    
        .bar:before {
            transform: translateY(-9px);
        }
    
        .bar:after {
            transform: translateY(9px);
        }
    
        .main{
            position: relative;
            width: 100%;
            left: 0;
            z-index: 5;
            overflow: hidden;
            transform-origin: left;
            transform-style: preserve-3d;
            transition: 0.5s;
        }
    
        header{
            min-height: 100vh;
            width: 100%;
            background-color: grey;
        }
    
        .overlay{
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    
        .container.active .bar{
            transform: rotate(360deg);
            background-color: transparent;
        }
    
        .container.active .bar:before{
            transform: translateY(0) rotate(45deg);
        }
    
        .container.active .bar:after{
            transform: translateY(0) rotate(-45deg);
        }
    
        .container.active .main{
            animation: main-animation 0.5s ease;
            left: 350px;
            cursor: pointer;
            transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
        }
    
        @keyframes main-animation{
            from{
                transform: translate(0);
            }
    
            to{
                transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
            }
        }
    
        .links{
            position: absolute;
            width: 20%;
            right: 0;
            top: 0;
            height: 100vh;
            z-index: 2;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    
        ul{
            list-style: none;
        }
    
        .links a{
            text-decoration: none;
            color: #fcec0c;
            padding: 0.7rem 0;
            display: inline-block;
            font-size: 1rem;
            font-weight: 300;
            text-transform: uppercase;
            letter-spacing: 1px;
            transition: 0.3s;
            opacity: 0;
            transform: translateY(10px);
            animation: hide 0.5s forwards ease;
        }
    
        .links a:hover{
            color: #978d01;
        }
    
        .container.active .links a{
            animation: appear 0.5s forwards ease var(--i);
        }
    
        @keyframes appear{
            from{
                opacity: 0;
                transform: translateY(10px);
            }
            to{
                opacity: 1;
                transform: translateY(0px);
            }
        }
    
        @keyframes hide{
            from{
                opacity: 1;
                transform: translateY(0px);
            }
            to{
                opacity: 0;
                transform: translateY(10px);
            }
        }
    
        .shadow{
            position: absolute;
            width: 100%;
            height: 100vh;
            top: 0;
            left: 0;
            transform-style: preserve-3d;
            transform-origin: left;
            transition: 0.5s;
            background-color: white;
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }
    
        .shadow.one{
            z-index: -1;
            background-color: red;
        }
    
    
        .shadow.two{
            z-index: -2;
            background-color: blue;
        }
    
        .container.active .shadow.one{
            animation: shadow-one 0.6s ease-out;
            left: 100px;
            transform: perspective(1300px) rotateY(20deg) translateZ(215px) scale(0.5);
        }
    
        @keyframes shadow-one{
            0%{
                transform: translate(0);
            }
    
            5%{
                transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
            }
    
            100%{
                transform: perspective(1300px) rotateY(20deg) translateZ(215px) scale(0.5);
            }
        }
    
        .container.active .shadow.two{
            animation: shadow-two 0.6s ease-out;
            left: -25px;
            transform: perspective(1300px) rotateY(20deg) translateZ(120px) scale(0.5);
        }
    
        @keyframes shadow-two{
            0%{
                transform: translate(0);
            }
    
            20%{
                transform: perspective(1300px) rotateY(20deg) translateZ(310px) scale(0.5);
            }
    
            100%{
                transform: perspective(1300px) rotateY(20deg) translateZ(120px) scale(0.5);
            }
        }
    
        .container.active .main:hover + .shadow.one{
            transform: perspective(1300px) rotateY(20deg) translateZ(230px) scale(0.5);
        }
    
        .container.active .main:hover{
            transform: perspective(1300px) rotateY(20deg) translateZ(340px) scale(0.5);
        }
    
        .bottom{
            position: relative;
            width: 100%;
            height: 150px;
            display: none;
        }
    
        .show{
            display: flex;
            justify-content: center;
            align-items: center;
            top: -125px;
        }
    
        .arrow{
            font-size: 64px;
            margin: 0 200px;
            cursor: pointer;
            z-index: 10;
            border-radius: 50%;
            color: #fcec0c;
        }
    
        .arrow:hover .far{
            color: #978d01;
        }
    <img src="" alt="">
    <div class="container">
        <div class="navbar">
            <div class="hamburger-menu">
                <div class="bar"></div>
            </div>
        </div>
    
        <div class="main-container">
            <div class="main">
                <header>
                    <div class="overlay"></div>
                </header>
            </div>
    
            <div class="shadow one"></div>
            <div class="shadow two"></div>
    
            <div class="bottom">
                <div class="arrow left" data-val="-1">L</div>
                <div class="arrow right" data-val="-1">R</div>
            </div>
        </div>
    
        <div class="links">
            <ul>
                <li>
                    <a href="#" style="--i: 0.05s;">Home</a>
                </li>
                <li>
                    <a href="#" style="--i: 0.1s;">Services</a>
                </li>
                <li>
                    <a href="#" style="--i: 0.15s;">Portfolio</a>
                </li>
                <li>
                    <a href="#" style="--i: 0.2s;">Testimonials</a>
                </li>
            </ul>
        </div>
    </div>

    • 3

相关问题

  • 第二个 Instagram 按钮的 CSS 属性

  • 由于模糊,内容不可见

  • 弹出队列。消息显示不正确

  • 是否可以在 for 循环中插入提示?

  • 如何将 JSON 请求中的信息输出到数据表 Vuetify vue.js?

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    表格填充不起作用

    • 2 个回答
  • Marko Smith

    提示 50/50,有两个,其中一个是正确的

    • 1 个回答
  • Marko Smith

    在 PyQt5 中停止进程

    • 1 个回答
  • Marko Smith

    我的脚本不工作

    • 1 个回答
  • Marko Smith

    在文本文件中写入和读取列表

    • 2 个回答
  • Marko Smith

    如何像屏幕截图中那样并排排列这些块?

    • 1 个回答
  • Marko Smith

    确定文本文件中每一行的字符数

    • 2 个回答
  • Marko Smith

    将接口对象传递给 JAVA 构造函数

    • 1 个回答
  • Marko Smith

    正确更新数据库中的数据

    • 1 个回答
  • Marko Smith

    Python解析不是css

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5