swiper调整左右滑动按钮的位置

swiper本来的左右滑动按钮是跟slide重合的。
先看一下最终效果:
在这里插入图片描述

说一下大概的思路。
就是在swiper容器的最外层再加一层div 然后把左右滑动的按钮放在跟swiper平级。
在这里插入图片描述

代码:
css:

		.swiper-father {
            width: 80%;
            height: 15%;
            top:75%;
            margin-left: auto;
            margin-right: auto;
            z-index: 9999;
            position: relative;
        }

        /*轮播按钮属性*/
        .swiper-container {
            width: 90%;
            height: 100%;
            z-index: 9999;
        }

        .swiper-slide{
            text-align: center;
            font-size: 18px;
            /*设置背景图片 及自适应*/
            background: url("/assets/images/buttonStyle.jpg") no-repeat;
            border-style: none;
            background-size:cover;
            -webkit-background-size:cover;
            -o-background-size:cover;
            background-position:center;

            height: calc((100% - 50px) / 2);
            display: flex;
            justify-content: center;
            align-items: center;
        }

这里宽度自己设置,不能设置100% 是为了给滑动按钮留出空间

html:

<#--地图下方的轮播按钮-->
<div class="swiper-father">
    <div class="swiper-container">
        <div class="swiper-wrapper" id="btnCon">
            <#list roomList as room>
                <button class="swiper-slide" onclick="findPoint(this)" value="${room.mapId}" type="submit">${room.roomName}</button>
            </#list>
        </div>
    </div>
    <!-- 轮播按钮 -->
    <div class="swiper-button-next"></div>
    <div class="swiper-button-prev"></div>
</div>

js:

    /*初始化轮播按钮*/
    var swiper = new Swiper('.swiper-container', {
        slidesPerView: 4,   //一行显示四个
        slidesPerColumn: 2, //显示两行
        spaceBetween: 30,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

散装程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值