vue图片轮播滚动(animejs)

javascript 复制代码
<template>
  <div class="case-hzhb">
    <div class="title">{{ title }}</div>
    <div class="case-hzhb-content">
      <div></div>
      <div></div>
      <div class="wrapper">
        <div class="boxes">
          <div v-for="(item, index) in boxList" :key="index" class="box">
            <img :src="getImageUrl(item)" alt="" />
          </div>
        </div>
      </div>
      <div class="wrapper">
        <div class="boxes">
          <div v-for="(item, index) in boxList2" :key="index" class="box2">
            <img :src="getImageUrl(item)" alt="" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { onMounted, ref, defineProps } from 'vue'
  import anime from 'animejs'

  let props = defineProps({
    //
    title: {
      type: String,
      default: '客户信赖的合作伙伴',
    },
  })

  const boxList = ref([
    'cooperate-img1.png',
    'cooperate-img2.png',
    'cooperate-img7.png', //
    'cooperate-img4.png',
    'cooperate-img5.png',
    'cooperate-img6.png',
    'cooperate-img7.png',
    'cooperate-img8.png',
    'cooperate-img9.png',
    'cooperate-img10.png',
    'cooperate-img11.png',
  ])
  const boxList2 = ref([
    'cooperate-img12.png',
    'cooperate-img13.png',
    'cooperate-img14.png',
    'cooperate-img15.png',
    'cooperate-img16.png',
    'cooperate-img17.png',
    'cooperate-img18.png',
    'cooperate-img19.png',
    'cooperate-img20.png',
    'cooperate-img21.png',
    'cooperate-img22.png',
  ])

  const animeFu = (boxClass = '.box', dir = 'right', duration = 24000) => {
    let xTrans = []
    let xT = 260
    anime.set(boxClass, {
      translateX: function (el, i, l) {
        xTrans[i] = { x: i * xT }
        return i * xT
      },
    })

    let x = 260 * xTrans.length
    anime({
      targets: xTrans,
      duration: duration, //走一周持续时间
      easing: 'linear',
      x: dir === 'right' ? `+=${x}` : `-=${x}`,
      loop: true,
      update: function () {
        anime.set(boxClass, {
          translateX: function (el, i, l) {
            return dir === 'right' ? xTrans[i].x % x : (xTrans[i].x + x) % x
          },
        })
      },
    })
  }

  const getImageUrl = (url) => {
    return new URL(`../assets/image/partners/${url}`, import.meta.url).href
  }
  onMounted(() => {
    animeFu('.box', 'right')
    animeFu('.box2', 'left')
  })
</script>

<style lang="scss" scoped>
  .case-hzhb {
    width: 100%;
    > .title {
      font-size: 40px;
      font-weight: bold;
      color: #202531;
      margin: 0 auto;
      text-align: center;
      padding-top: 20px !important;
    }
    &-content {
      position: relative;
      max-width: 2560px;
      height: 280px;
      margin: 50px auto 40px;
      // border: 1px solid;
      > div:nth-child(1) {
        position: absolute;
        left: 0;
        z-index: 1;
        width: 64px;
        height: 280px;
        background: linear-gradient(
          to right,
          rgba(255, 255, 255, 1),
          rgba(255, 255, 255, 0)
        );
      }
      > div:nth-child(2) {
        position: absolute;
        right: 0;
        z-index: 1;
        width: 64px;
        height: 280px;
        background: linear-gradient(
          to left,
          rgba(255, 255, 255, 1),
          rgba(255, 255, 255, 0)
        );
      }

      .wrapper {
        width: 100%;
        height: 100px;
        position: relative;
        margin: 30px auto 0;
        // background: #ccc;
        overflow: hidden;
        .boxes {
          position: relative;
          left: -200px;
          .box,
          .box2 {
            width: 240px;
            height: 96px;
            background-color: #ffffff;
            // border: solid 2px #f7f7f9;
            position: absolute;
            > img {
              width: 100%;
              height: 100%;
            }
          }
        }
      }
    }
  }
</style>
相关推荐
CodeSheep3 分钟前
当了leader才发现,大厂最想裁掉的,不是上班总迟到的,也不是下班搞失联的,而是经常把这3句话挂在嘴边的
前端·后端·程序员
吃饺子不吃馅7 分钟前
✨ 你知道吗?SVG 里藏了一个「任意门」——它就是 foreignObject! 🚪💫
前端·javascript·面试
IT_陈寒1 小时前
Python开发者必须掌握的12个高效数据处理技巧,用过都说香!
前端·人工智能·后端
gnip8 小时前
企业级配置式表单组件封装
前端·javascript·vue.js
一只叫煤球的猫9 小时前
写代码很6,面试秒变菜鸟?不卖课,面试官视角走心探讨
前端·后端·面试
excel10 小时前
Three.js 材质(Material)详解 —— 区别、原理、场景与示例
前端
掘金安东尼10 小时前
抛弃自定义模态框:原生Dialog的实力
前端·javascript·github
hj5914_前端新手14 小时前
javascript基础- 函数中 this 指向、call、apply、bind
前端·javascript
薛定谔的算法14 小时前
低代码编辑器项目设计与实现:以JSON为核心的数据驱动架构
前端·react.js·前端框架
Hilaku14 小时前
都2025年了,我们还有必要为了兼容性,去写那么多polyfill吗?
前端·javascript·css