如何快速生成一个H5滑动的卡片

javascript 复制代码
 <ul class="combo">
        <li v-for="(item, index) in arr" :key="index">
          <div class="combo-name">{{ item.A }}</div>
          <div class="combo-price">{{ item.B }}</div>
          <div class="combo-button" @click="handleImmediatelyData(item, idx)">
            立即办理
          </div>
        </li>
      </ul> 

  arr: [
        {
          A: "套餐打折",
          B: "五G套餐专享",
       
        },
        {
          A: "套餐打折",
          B: "五G套餐专享",
          
        },
        {
          A: "套餐打折",
          B: "五G套餐专享",
          
        },
        {
          A: "套餐打折",
          B: "五G套餐专享",
       
        },
        {
          A: "套餐打折",
          B: "五G套餐专享",
    
        },
        {
          A: "套餐打折",
          B: "五G套餐专享",
   
        },
        {
          A: "套餐打折",
          B: "五G套餐专享",
  
        },
        {
          A: "套餐打折",
          B: "五G套餐专享",
  
        },
        {
          A: "套餐打折",
          B: "五G套餐专享",

        },
      ],




  .combo {
      width: 100%;
      // height: 86px;
      box-shadow: 0px 4px 6px 0px rgba(0, 0, 0, 0.05);
      border-radius: 0px 0px 0px 0px;
      opacity: 1;
      margin-top: 12px;
      display: -webkit-box;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      .combo::-webkit-scrollbar {
        display: none;
        // width: 0px;
        opacity: 0;
      }
      li {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        text-align: center;
        width: 90px;
        height: 90px;
        // background: linear-gradient(320deg, #ffffff 0%, #f9daa4 100%);
        background-color: #fff;
        border-radius: 8px 8px 8px 8px;
        opacity: 1;
        // border: 1px solid #ffffff;
        margin-left: 10px;
        margin-bottom: 5px;
        &:first-child{
          margin-left: 0;
        }
        .combo-title {
          line-height: 20px;
          font-size: 14px;
          font-weight: 400;
          color: blue;
        }
        .combo-price {
          font-size: 13px;
          font-weight: 600;
          color: #fca418;
          height: 20px;
          line-height: 20px;
          margin-top: 6px;
          margin-bottom: 6px;
        }
        .combo-button {
          border-radius: 40px 40px 40px 40px;
          font-size: 12px;
          background: #fca418;
          font-weight: 400;
          color: #fff;
          line-height: 20px;
          width: 65px;
        }
      }
    }

当要对滚动做一些处理的时候可以参考下面的代码

javascript 复制代码
    handleScroll(event) {
          // 获取滚动的距离
      const scrollDistance = event.target.scrollLeft;
        当前视口的宽度
      var viewportWidth = window.innerWidth || document.documentElement.clientWidth;

      // 获取第一个 li 元素的宽度
      const firstItemWidth = this.$refs.comboList.querySelector('.combo li:first-child').clientWidth;
      // console.log(scrollDistance,'滚动');
      // 判断滚动的距离是否超过第一个盒子的宽度,外边距10*(n-1)+视口内边距20 = 30+20
      if (scrollDistance >= 4*firstItemWidth-viewportWidth+50) {
        console.log(scrollDistance,viewportWidth-20,4*firstItemWidth,'滚动距离超过第一个盒子的宽度!');
        // 在这里进行你的打印操作或其他操作
      }
    },
相关推荐
l1x1n01 小时前
No.3 笔记 | Web安全基础:Web1.0 - 3.0 发展史
前端·http·html
昨天;明天。今天。1 小时前
案例-任务清单
前端·javascript·css
惜.己2 小时前
javaScript基础(8个案例+代码+效果图)
开发语言·前端·javascript·vscode·css3·html5
秋殇与星河3 小时前
CSS总结
前端·css
神之王楠4 小时前
如何通过js加载css和html
javascript·css·html
茶卡盐佑星_5 小时前
meta标签作用/SEO优化
前端·javascript·html
金灰5 小时前
HTML5--裸体回顾
java·开发语言·前端·javascript·html·html5
Zheng1137 小时前
【可视化大屏】将柱状图引入到html页面中
javascript·ajax·html
软件开发技术深度爱好者8 小时前
用HTML5+CSS+JavaScript庆祝国庆
javascript·css·html5
昨天;明天。今天。14 小时前
案例-表白墙简单实现
前端·javascript·css