九宫格九图动画,不是八图点中间抽奖!!!!!!

element-ui只有单方向轮播图(也可能可以实现九宫格但我不知道)

native-ui有九宫格轮播图

效果如native效果

<n-carousel
          autoplay
          dot-type="line"
          :interval="Number(carouselInterval)"
        >
          <img
            v-for="(item, i) in carouselImgList"
            :key="i"
            class="go-login-carousel-img"
            :src="getImageUrl(item, 'login')"
            alt="image"
          />
        </n-carousel>

若需要在vue2写九宫格轮播图须纯手写(无须下载插件,纯底层JS和DOM代码)

HTML

<div class="go-login-box-bg">

      <aside class="bg-slot"></aside>

      <aside class="bg-img-box">
        <div class="grid-container">
          <div class="grid-item" v-for="(item, index) in bgList" :key="index">
            <img :src="getImageUrl({item:item,folder:'charts'})">
          </div>
        </div>
      </aside>

    </div>

CSS

.go-login-box-bg {
    z-index: 0;
    position: fixed;
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100vw;
    height: 100vh;
    background: url(../../assets/loginbg1.png) no-repeat;
    background-size: cover; /* 使背景图自适应 */
    background-position: center; /* 将背景图居中 */
    .bg-slot{
        width:30%;
      }
    .bg-img-box{
        position: relative;
        display: flex;
        flex-wrap: wrap;
        width: 60%;
        margin-right: -18%;
       
        .grid-container {
          margin-left: 15%;
              width: 600px;
              height: 600px;
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            grid-gap: 10px;
          }
          .grid-item {
            width: 100%;
            height: 100%;
            background-size: cover;
            transition: transform 1s ease-in-out;
            img{
              margin-right: 20px;
              margin-top: 20px;
              width: 230px;
              border-radius: 16px;
              opacity: 0.9;
            }
          }
        
       
    }
    
}

JS

const gridItems = document.querySelectorAll('.grid-item');
    console.log(gridItems)
      function shuffle(array) {
        let currentIndex = array.length, randomIndex;

        while (currentIndex !== 0) {
          randomIndex = Math.floor(Math.random() * currentIndex);
          currentIndex--;

          [array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
        }

        return array;
      }

      function updateGrid() {
        const shuffledItems = shuffle(Array.from(gridItems));
        gridItems.forEach((item, index) => {
          item.style.transform = `translate(${shuffledItems[index].offsetLeft - item.offsetLeft}px, ${shuffledItems[index].offsetTop - item.offsetTop}px)`;
        });
      }
      window.setInterval(updateGrid, 2000);

综上就是html+css+js实现九宫格轮播图

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值