zoukankan      html  css  js  c++  java
  • 手机端--swiper一屏展示下个轮播的一半的效果

    手机屏展示这样的效果,用swiper去实现,

    <template>
      <view class="container">
        <view
          class="mas-promo-swiper-scroll-wrapper"
          :style="{ transform:'translateX(' +swiperMarginLeft+'rpx)'}"   //最主要的就是设置 previous-margin next-margin的值!并且设置父元素的平移距离,,并且在滑动到第一个或者最后一个时更改相对应的值!
        >
          <swiper
            class="swiper-wrapper"
            previousMargin="30rpx"
            nextMargin="30rpx"
            @change="changeSwiperItem"
          >
            <swiper-item
              v-for="(item, index) in list"
              :key="index"
              class="swiper-item"
            >
              <view class="mas-promo-swiper-item-image-wrapper">
                <image :src="item.elememtIcon" />
              </view>
            </swiper-item>
          </swiper>
        </view>
      </view>
    </template>
    
    <script lang="ts">
    import { Vue, Component, Prop } from 'vue-property-decorator';
    import * as util from '@/util/util.ts';
    
    @Component
    export default class mySwiper extends Vue {
      private swiperMarginLeft: Number = -48;
    
      private interval: any = 5000;
    
      private allowClick: any = true;
    
      private currentIndex: Number = 0;
      private list: any = [];
      changeSwiperItem(e) {
        // TODO 滑动的同时动态修改margin-left会有抖动
        var itemId = e.detail.current;
        var bannerList = this.list;
        this.currentIndex = itemId;
    
        if (itemId === 0) {
          this.swiperMarginLeft = -48;
        } else if (itemId === bannerList.length - 1) {
          this.swiperMarginLeft = 48;
        } else {
          this.swiperMarginLeft = 0;
        }
      }
    }
    </script>
    
    <style lang="less" scoped>
    .container {
      overflow: hidden;
    }
    
    .mas-promo-swiper-scroll-wrapper {
      transition: all 0.3s ease-out;//记得为父元素加个动画!这样在改变父元素的平移距离的时候就不会有跳动感觉了
    }
    .swiper-wrapper {
      overflow: visible;
    }
    .swiper-item {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    .mas-promo-swiper-item-image-wrapper image {
      display: block;
       620rpx;
      height: 164rpx;
      border-radius: 16rpx;
    }
    </style>
  • 相关阅读:
    JavaScript数组API
    爱上经典之王梦麟《阿美阿美》
    爱上经典之《蜗牛与黄鹂鸟》
    爱上经典之《兰花草》
    爱上经典之《让我们看云去》
    爱上经典之卓依婷《三月里的小雨》
    爱上经典之孟庭苇《冬季到台北来看雨》
    有故事看SQA作用
    转自scmlife趣谈质量管理与工程改进面试
    Mysql之批处理
  • 原文地址:https://www.cnblogs.com/lvlvlv/p/14441805.html
Copyright © 2011-2022 走看看