基于css的Grid布局和vue实现点击左移右移轮播过渡动画效果

在这里插入图片描述

直接上代码,以下代码基于vue2,需要Vue3或者react可以使用国内直连GPT/Claude来帮你转换下

代码如下:

// ScrollCardsGrid.vue
<template>
  <div class="scroll-cards-container">
    <!-- 左箭头 -->
    <div v-show="showLeftArrow" class="scroll-arrow left-arrow" @click="handleScrollLeft">
      <i class="arrow-icon"></i>
    </div>

    <!-- 卡片容器 -->
    <div class="cards-container" ref="cardsContainer" @scroll="handleScroll">
      <div class="cards-grid">
        <div v-for="(card, index) in cards" :key="index" class="card">
          <div class="card-content">
            <img :src="card.icon" class="card-icon" :alt="card.title" />
            <div class="card-info">
              <h3 class="card-title">{{ card.title }}</h3>
              <p class="card-description">{{ card.description }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 右箭头 -->
    <div v-show="showRightArrow" class="scroll-arrow right-arrow" @click="handleScrollRight">
      <i class="arrow-icon"></i>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ScrollCardsGrid',
  data() {
    return {
      showLeftArrow: false,
      showRightArrow: false,
      scrollStep: 300,
      cards: [
        {
          icon: '/path/to/llama.png',
          title: 'Llama-3.1-405B',
          description: '作为Meta的Llama 3.1系列的巅峰之作...'
        },
        {
          icon: '/path/to/claude.png',
          title: 'Claude-3.5-Hai',
          description: 'The latest generation of Anthropic\'s fastest...'
        },
        {
          icon: '/path/to/chatgpt.png',
          title: 'ChatGPT-4o-La',
          description: 'OpenAI的最强大的模型...'
        },
        {
          icon: '/path/to/gpt4.png',
          title: 'GPT-4o-Mini',
          description: 'OpenAI的最新模型...'
        },
        {
          icon: '/path/to/gemini.png',
          title: 'Gemini-1.5-Pro',
          description: 'Google的Gemini系列多模态模型...'
        },
        {
          icon: '/path/to/mistral.png',
          title: 'Mistral-Medium',
          description: 'Mistral AI的中等大小模型...'
        },
        {
          icon: '/path/to/gemini-flash.png',
          title: 'Gemini-1.5-Flash',
          description: 'Powered by gemini-1.5-flash-002...'
        },
        {
          icon: '/path/to/llama70b.png',
          title: 'Llama-3.1-70B',
          description: '作为Meta的Llama 3.1系列的中型成员...'
        }
      ]
    }
  },
  mounted() {
    this.checkArrows()
    window.addEventListener('resize', this.checkArrows)
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.checkArrows)
  },
  methods: {
    checkArrows() {
      const container = this.$refs.cardsContainer
      if (!container) return
      
      this.showLeftArrow = container.scrollLeft > 0
      this.showRightArrow = 
        container.scrollLeft < (container.scrollWidth - container.clientWidth)
    },
    handleScroll() {
      this.checkArrows()
    },
    handleScrollLeft() {
      const container = this.$refs.cardsContainer
      container.scrollBy({
        left: -this.scrollStep,
        behavior: 'smooth'
      })
    },
    handleScrollRight() {
      const container = this.$refs.cardsContainer
      container.scrollBy({
        left: this.scrollStep,
        behavior: 'smooth'
      })
    }
  }
}
</script>

<style scoped>
.scroll-cards-container {
  position: relative;
  width: 600px;
  margin: 0 auto;
  margin-top: 200px;
  display: flex;
  align-items: center;
}

.cards-container {
  width: 100%;
  overflow-x: auto;
  scroll-behavior: smooth;
  /* 隐藏滚动条但保持功能 */
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 16px 0;
}

.cards-container::-webkit-scrollbar {
  display: none;
}

.cards-grid {
  display: grid;
  /* 固定两行 */
  grid-template-rows: repeat(2, 1fr);
  /* 自动填充列,每列最小宽度280px */
  grid-auto-flow: column;
  grid-auto-columns: 280px;
  gap: 16px;
  padding: 0 16px;
}

.card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  /* 确保卡片高度一致 */
  height: 88px;
  box-sizing: border-box;
}

.card-content {
  display: flex;
  gap: 12px;
  height: 100%;
}

.card-icon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
}

.card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.card-title {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}

.card-description {
  margin: 0;
  font-size: 14px;
  color: #6b7280;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}

.scroll-arrow {
  position: absolute;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  z-index: 1;
  transition: all 0.3s ease;
}

.scroll-arrow:hover {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.left-arrow {
  left: -20px;
}

.right-arrow {
  right: -20px;
}

.arrow-icon {
  font-style: normal;
  color: #374151;
}

/* 适配移动端 */
@media (max-width: 640px) {
  .cards-grid {
    grid-template-rows: 1fr; /* 在移动端切换为单行 */
  }
  
  .scroll-arrow {
    display: none; /* 在移动端隐藏箭头 */
  }
}
</style>
### IntelliJ IDEA 启动报错解决方案 #### Java 编译器内部错误 当遇到 `Error:java: Compilation failed: internal java compiler error` 错误时,这通常意味着编译过程遇到了不可预见的问题。可能的原因包括但不限于插件冲突、Java 版本兼容性问题或是 IDE 配置文件损坏。建议尝试重新安装最新版本的 JDK 和 IntelliJ IDEA,并确保所有插件都是最新的稳定版[^1]。 #### 命令行过长 对于 “Command line is too long.” 这样的错误信息,表明传递给 JVM 的参数超出了操作系统的命令长度限制。可以通过调整构建配置来减少传递到命令行上的参数数量;另一种方法是在项目的 VM options 中设置 `-Dfile.encoding=UTF-8 -XX:+UseConcMarkSweepGC -Xmx512m -Xms512m` 参数以优化内存分配策略,从而间接解决问题[^2]。 #### Lombok 注解处理器未启用 如果看到类似于 `Lombok Requires Annotation Processing` 的警告,则说明当前项目尚未开启注解处理支持。前往 **File | Settings (Ctrl+Alt+S)** 菜单下的 **Build, Execution, Deployment | Compiler | Annotation Processors** 页面勾选 Enable annotation processing 复选框即可激活该特性[^4]。 #### 更新后的 GC 日志路径问题 在某些情况下,更新后的 IntelliJ IDEA 可能会因为环境变量的变化而无法正常读取或写入日志文件。比如 `$USER_HOME/logs/idea/idea_gc.log` 应改为 `/Users/tom/logs/idea/idea_gc.log` 使用绝对路径代替相对路径可以有效规避此类情况的发生[^5]。 #### 总结与预防措施 为了防止上述及其他潜在问题的发生,在日常开发工作中应当保持软件及其依赖项处于最新状态,定期清理缓存数据以及合理规划工作区布局等良好习惯有助于提高工作效率并降低故障发生的概率[^3]。 ```bash # 清理IntelliJ IDEA缓存的方法之一 rm -rf ~/.IdeaIC*/system/cache/ ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

吉吉安

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

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

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

打赏作者

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

抵扣说明:

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

余额充值