首页 > 其他分享 >html css js 手写简易轮播图

html css js 手写简易轮播图

时间:2023-01-19 15:22:05浏览次数:46  
标签:carouselR about 轮播 js width html let carousel ber

源码下载:https://github.com/pine007/source-codes/blob/main/html-css-js-手写简易轮播图.zip

1、效果

2、编码

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>轮播图</title>

    <style>
        .about-ber {
            width: 100%;
            height: 800px;
            background: #FFFFFF;
            text-align: center;
            padding-top: 40px;
            overflow-x: hidden;
        }

        .about-ber-txt p span {
            font-family: LinotypeDidot, serif;
            font-size: 36px;
            line-height: 60px;
            font-weight: 400;
            color: #2D302A;
        }

        .about-ber-txt p {
            font-size: 20px;
            line-height: 14px;
            color: #8A8C88;
        }

        .about-ber-carousels {
            position: relative;
        }

        .about-ber-carousel {
            position: absolute;
            transition: transform 0.35s;
            top: 60px;
            width: 50%;
            background-color: #EFF0E9
        }

        .about-ber-carousel1 {
            transform: translate3d(-100%, 0, 0) scale(0.81);
            opacity: 0;
            z-index: 1;
        }

        .about-ber-carousel2 {
            transform: translate3d(-46%, 0, 0) scale(0.81);
            z-index: 2;
        }

        .about-ber-carousel3 {
            transform: translate3d(50%, 0, 0) scale(0.81);
            top: 0;
        }

        .about-ber-carousel4 {
            transform: translate3d(146%, 0, 0) scale(0.81);
            z-index: 2;
        }

        .about-ber-carousel5 {
            transform: translate3d(200%, 0, 0) scale(0.81);
            opacity: 0;
            z-index: 1;
        }

        .about-ber-carousel-img {
            float: left;
            width: 50%;
            max-width: 440px;
        }

        .about-ber-carousel-img img {
            width: 100%;
            vertical-align: bottom;
        }

        .about-ber-carousel-txt {
            float: left;
            width: 50%;
            max-width: 440px;
            text-align: center;
        }

        .about-ber-carousel-txt img {
            display: block;
            margin: 30px 20px;
            width: 18px;
            height: 18px;
        }

        .about-ber-btn {
            position: absolute;
            top: 500px;
            left: 48.5%;
            z-index: 3;
        }

        .about-ber-btn img {
            width: 28px;
            cursor: pointer;
        }
    </style>

</head>
<body>
<div class="about-ber">
    <div class="about-ber-txt">
        <p><span># Berladies</span></p>
        <p>Join the journey and tag or follow #berladies on Instagram!</p>
        <p>Share confidence, encouragement, and empowerment with other ladies just like you and your feedback to
            help us improve our products together.</p>
    </div>
    <div class="about-ber-carousels">
        <div class="about-ber-carousel about-ber-carousel1">
            <div>
                <div class="about-ber-carousel-img">
                    <img src="./images/v1.jpg" alt=""/>
                </div>
                <div class="about-ber-carousel-txt">
                    <p><span>About Sustainability p1</span></p>
                    <p>
                        We believe offer a wide range of styles and trends aren't everything, but above all make
                        environmental
                        progress for a better tomorrow.
                    </p>
                </div>
            </div>
        </div>
        <div class="about-ber-carousel about-ber-carousel2">
            <div>
                <div class="about-ber-carousel-img">
                    <img src="./images/v2.jpg" alt=""/>
                </div>
                <div class="about-ber-carousel-txt">
                    <p><span>About Sustainability p2</span>
                    <p>
                        We believe offer a wide range of styles and trends aren't everything, but above all make
                        environmental
                        progress for a better tomorrow.
                    </p>
                </div>
            </div>
        </div>
        <div class="about-ber-carousel about-ber-carousel3">
            <div>
                <div class="about-ber-carousel-img">
                    <img src="./images/v3.jpg" alt=""/>
                </div>
                <div class="about-ber-carousel-txt">
                    <p><span>About Sustainability p3</span></p>
                    <p>
                        We believe offer a wide range of styles and trends aren't everything, but above all make
                        environmental
                        progress for a better tomorrow.
                    </p>
                </div>
            </div>
        </div>
        <div class="about-ber-carousel about-ber-carousel4">
            <div>
                <div class="about-ber-carousel-img">
                    <img src="./images/v4.jpg" alt=""/>
                </div>
                <div class="about-ber-carousel-txt">
                    <p><span>About Sustainability p4</span></p>
                    <p>
                        We believe offer a wide range of styles and trends aren't everything, but above all make
                        environmental
                        progress for a better tomorrow.
                    </p>
                </div>
            </div>
        </div>
        <div class="about-ber-carousel about-ber-carousel5">
            <div>
                <div class="about-ber-carousel-img">
                    <img src="./images/v5.jpg" alt=""/>
                </div>
                <div class="about-ber-carousel-txt">
                    <p><span>About Sustainability p5</span></p>
                    <p>
                        We believe offer a wide range of styles and trends aren't everything, but above all make
                        environmental
                        progress for a better tomorrow.
                    </p>
                </div>
            </div>
        </div>
        <div class="about-ber-btn">
            <img id="prev" src="./images/arrow-l.png" alt="" onclick="prevImg()"/>&nbsp;
            <img id="next" src="./images/arrow-r.png" alt="" onclick="nextImg()"/>
        </div>
    </div>
</div>


<script>
    //--轮播图点击事件

    let carousel = 'about-ber-carousel';
    let carouselR = ['about-ber-carousel1', 'about-ber-carousel2', 'about-ber-carousel3', 'about-ber-carousel4', 'about-ber-carousel5'];

    //上一张
    function prevImg() {
        carouselR.push(carouselR[0]);
        carouselR.shift();
        let lis = document.getElementsByClassName(carousel)
        for (let i = 0; i < lis.length; i++) {
            lis[i].setAttribute('class', carousel + ' ' + carouselR[i])
        }
    }

    //下一张
    function nextImg() {
        carouselR.unshift(carouselR[4])
        carouselR.pop()
        let lis = document.getElementsByClassName(carousel)
        for (let i = 0; i < lis.length; i++) {
            lis[i].setAttribute('class', carousel + ' ' + carouselR[i])
        }
    }
</script>

</body>
</html>

标签:carouselR,about,轮播,js,width,html,let,carousel,ber
From: https://www.cnblogs.com/pine007/p/17061560.html

相关文章

  • ElementUI 轮播图
    一、概述因项目需求,需要增加轮播图,官方demo效果如下: 但这个不是我们想要的,我们需要的是这样的。  二、代码实现需要在原有的基础上,修改页面样式才行。test.vu......
  • python提取json中键值
    0X00 样例数据:{'d':{'__type':'st','YX':"<tableid='tabyxlist'><tr><tdclass='tdth'>院校名称</td><tdclass='tdth'>计划数</td></tr><trid=......
  • js structuredClone All In One
    jsstructuredCloneAllInOnedeepcopy/deepclone_.cloneDeepJSON.parse&JSON.stringifystrucuredClonehttps://developer.mozilla.org/en-US/docs/Glossar......
  • 在.net core中开发web页面,更新html代码刷新不生效的问题
    因为在.netcore之后的版本,程序都是以控制台应用程序的方式存在,所以一些老的项目升级后,会出现这样的情况,解决方法,在nuget中引入Microsoft.AspNetCore.Mvc.Razor.Run......
  • go json
    转化为json格式funcMarshal(vinterface{})([]byte,error)//将v(一般为结构体)转化为json格式//json.gopackagemainimport("encoding/json""fm......
  • JavaScript精简(基于node.js)
    目录1、基本语法2、变量3、数据类型3.1、数字型Number3.2、字符串类型String3.3、布尔型Boolean3.4、Undefined、Null3.5、获取变量的数据类型3.6、数据类型的转化4、运......
  • 坑!你不知道的JSON解析
    背景最近在对接国内的外卖平台,代码啥的正常开发、测试、上线都没发现什么异常的。突然,最近有运维反馈说漏了单据,一开始我以为是外卖平台那边接口异常,拉单延迟导致的,就没怎......
  • 没有重复数字的全排列-js
    题目描述全排列,传入数字输出所有可能出现的情况思路分析经典回溯法例题采用闭包的方式记录总的结果(可以访问外部变量),记录每一层的结果,记录当前的深度,用记事本记录元......
  • nodejs 导出excel
    window.export=function(){layer.msg(MOD_PAGE_PATH+'/export');window.location=MOD_PAGE_PATH+'/export'......
  • 字符串全排列-js
    题目描述思路分析对于全排列类型的题我们都可以按照之前的思路去做,(全排列)。采用回溯的方法。这里的字符串我们也可以借助之前的函数,将字符串转为数组即可代码参考co......