| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <!-- -->
- <template>
- <div
- :class="`cardCom ${keyval}`"
- v-touch:swipe.left="moveSwiper"
- v-touch:swipe.right="moveSwiper"
- >
- <div
- v-for="(_, index) in cardData"
- :key="index"
- class="card"
- :style="`top:${index * 15}px;width:${100 - index * 5}%;opacity:${
- 1 - index * 0.2 <= 0 ? 0.1 : 1 - index * 0.2
- }; z-index: ${cardData.length - index};`"
- >
- <template v-if="index === 0">
- <slot :item="cardData[cardInd]" />
- <span class="page">{{ cardInd + 1 }} / {{ cardData.length }}</span>
- </template>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: "cardCom",
- props: {
- cardData: {
- type: Array,
- default: () => [],
- },
- keyval: {
- type: String,
- default: "",
- },
- },
- components: {},
- data() {
- //这里存放数据
- return {
- cardInd: 0,
- };
- },
- //监听属性 类似于data概念
- computed: {},
- //监控data中的数据变化
- watch: {},
- //方法集合
- methods: {
- // 封装一个滑动的方法
- moveSwiper(val) {
- let dom = document.querySelector(`.${this.keyval}`);
- if (!dom) return;
- dom.style.opacity = 0;
- setTimeout(() => {
- if (val === "right") {
- // 右滑减小
- if (this.cardInd === 0) this.cardInd = this.cardData.length - 1;
- else this.cardInd--;
- } else {
- //左滑增加
- if (this.cardInd < this.cardData.length - 1) this.cardInd++;
- else this.cardInd = 0;
- }
- dom.style.opacity = 1;
- }, 300);
- },
- },
- //生命周期 - 创建完成(可以访问当前this实例)
- created() {},
- //生命周期 - 挂载完成(可以访问DOM元素)
- mounted() {
- // 动态控制cardCom元素的高度
- this.$nextTick(() => {
- setTimeout(() => {
- let dom = document.querySelector(`.${this.keyval}`);
- dom.style.height = 535 + (this.cardData.length - 1) * 15 + "px";
- }, 300);
- });
- },
- beforeCreate() {}, //生命周期 - 创建之前
- beforeMount() {}, //生命周期 - 挂载之前
- beforeUpdate() {}, //生命周期 - 更新之前
- updated() {}, //生命周期 - 更新之后
- beforeDestroy() {}, //生命周期 - 销毁之前
- destroyed() {}, //生命周期 - 销毁完成
- activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
- };
- </script>
- <style lang="scss" scoped>
- .txt::-webkit-scrollbar {
- /*滚动条整体样式*/
- width: 8px; /*高宽分别对应横竖滚动条的尺寸*/
- height: 2px;
- }
- .txt::-webkit-scrollbar-thumb {
- /*滚动条里面小方块*/
- -webkit-box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
- background: #d9cdb6;
- }
- .txt::-webkit-scrollbar-track {
- /*滚动条里面轨道*/
- width: 0px;
- background: transparent;
- }
- .cardCom {
- margin-top: 80px;
- width: 100%;
- position: relative;
- transition: all 0.3s;
- }
- .card {
- background-color: #fff;
- box-shadow: 0px 2px 8px 6px #ccc;
- position: absolute;
- top: 0;
- left: 50%;
- transform: translateX(-50%);
- width: 100%;
- margin: 0 auto;
- display: flex;
- flex-direction: column;
- .page {
- opacity: 0.3;
- color: #b79550;
- position: absolute;
- font-weight: 700;
- right: 10px;
- bottom: 10px;
- font-size: 32px;
- }
- }
- </style>
|