You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
9.6 KiB
1 line
9.6 KiB
{"remainingRequest":"/Users/linhuakun/Downloads/nodejs/codewhy/node_modules/vue-loader/lib/index.js??vue-loader-options!/Users/linhuakun/Downloads/nodejs/codewhy/src/components/common/swiper/Swiper.vue?vue&type=style&index=0&id=bc58910a&scoped=true&lang=css&","dependencies":[{"path":"/Users/linhuakun/Downloads/nodejs/codewhy/src/components/common/swiper/Swiper.vue","mtime":1607666509048},{"path":"/Users/linhuakun/Downloads/nodejs/codewhy/node_modules/css-loader/dist/cjs.js","mtime":499162500000},{"path":"/Users/linhuakun/Downloads/nodejs/codewhy/node_modules/vue-loader/lib/loaders/stylePostLoader.js","mtime":499162500000},{"path":"/Users/linhuakun/Downloads/nodejs/codewhy/node_modules/postcss-loader/src/index.js","mtime":499162500000},{"path":"/Users/linhuakun/Downloads/nodejs/codewhy/node_modules/cache-loader/dist/cjs.js","mtime":499162500000},{"path":"/Users/linhuakun/Downloads/nodejs/codewhy/node_modules/vue-loader/lib/index.js","mtime":499162500000}],"contextDependencies":[],"result":[{"type":"Buffer","data":"base64:CgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCg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ACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA","file":"Swiper.vue","sourceRoot":"src/components/common/swiper","sourcesContent":["<template>\n <div id=\"hy-swiper\">\n <div class=\"swiper\" @touchstart=\"touchStart\" @touchmove=\"touchMove\" @touchend=\"touchEnd\">\n <slot></slot>\n </div>\n <slot name=\"indicator\">\n </slot>\n <div class=\"indicator\">\n <slot name=\"indicator\" v-if=\"showIndicator && slideCount>1\">\n <div v-for=\"(item, index) in slideCount\" class=\"indi-item\" :class=\"{active: index === currentIndex-1}\" :key=\"index\"></div>\n </slot>\n </div>\n </div>\n</template>\n\n<script>\n\texport default {\n\t\tname: \"Swiper\",\n props: {\n interval: {\n\t\t type: Number,\n default: 3000\n },\n animDuration: {\n\t\t type: Number,\n default: 300\n },\n moveRatio: {\n type: Number,\n default: 0.25\n },\n showIndicator: {\n type: Boolean,\n default: true\n }\n },\n data: function () {\n\t\t return {\n slideCount: 0, // 元素个数\n totalWidth: 0, // swiper的宽度\n swiperStyle: {}, // swiper样式\n currentIndex: 1, // 当前的index\n scrolling: false, // 是否正在滚动\n }\n },\n mounted: function () {\n // 1.操作DOM, 在前后添加Slide\n setTimeout(() => {\n this.handleDom();\n // 2.开启定时器\n this.startTimer();\n }, 500)\n },\n methods: {\n\t\t /**\n * 定时器操作\n */\n startTimer: function () {\n\t\t this.playTimer = window.setInterval(() => {\n\t\t this.currentIndex++;\n\t\t this.scrollContent(-this.currentIndex * this.totalWidth);\n }, this.interval)\n },\n stopTimer: function () {\n window.clearInterval(this.playTimer);\n },\n\n /**\n * 滚动到正确的位置\n */\n scrollContent: function (currentPosition) {\n // 0.设置正在滚动\n this.scrolling = true;\n\n // 1.开始滚动动画\n this.swiperStyle.transition ='transform '+ this.animDuration + 'ms';\n this.setTransform(currentPosition);\n\n // 2.判断滚动到的位置\n this.checkPosition();\n\n // 4.滚动完成\n this.scrolling = false\n },\n\n /**\n * 校验正确的位置\n */\n checkPosition: function () {\n window.setTimeout(() => {\n // 1.校验正确的位置\n this.swiperStyle.transition = '0ms';\n if (this.currentIndex >= this.slideCount + 1) {\n this.currentIndex = 1;\n this.setTransform(-this.currentIndex * this.totalWidth);\n } else if (this.currentIndex <= 0) {\n this.currentIndex = this.slideCount;\n this.setTransform(-this.currentIndex * this.totalWidth);\n }\n\n // 2.结束移动后的回调\n this.$emit('transitionEnd', this.currentIndex-1);\n }, this.animDuration)\n },\n\n /**\n * 设置滚动的位置\n */\n setTransform: function (position) {\n this.swiperStyle.transform = `translate3d(${position}px, 0, 0)`;\n this.swiperStyle['-webkit-transform'] = `translate3d(${position}px), 0, 0`;\n this.swiperStyle['-ms-transform'] = `translate3d(${position}px), 0, 0`;\n },\n\n /**\n * 操作DOM, 在DOM前后添加Slide\n */\n\t\t handleDom: function () {\n // 1.获取要操作的元素\n let swiperEl = document.querySelector('.swiper');\n let slidesEls = swiperEl&&swiperEl.getElementsByClassName('slide');\n // 2.保存个数\n this.slideCount = slidesEls&&slidesEls.length;\n\n // 3.如果大于1个, 那么在前后分别添加一个slide\n if (this.slideCount > 1) {\n let cloneFirst = slidesEls[0].cloneNode(true);\n let cloneLast = slidesEls[this.slideCount - 1].cloneNode(true);\n swiperEl.insertBefore(cloneLast, slidesEls[0]);\n swiperEl.appendChild(cloneFirst);\n this.totalWidth = swiperEl.offsetWidth;\n this.swiperStyle = swiperEl.style;\n }\n\n // 4.让swiper元素, 显示第一个(目前是显示前面添加的最后一个元素)\n this.setTransform(-this.totalWidth);\n },\n\n /**\n * 拖动事件的处理\n */\n touchStart: function (e) {\n // 1.如果正在滚动, 不可以拖动\n if (this.scrolling) return;\n\n // 2.停止定时器\n this.stopTimer();\n\n // 3.保存开始滚动的位置\n this.startX = e.touches[0].pageX;\n },\n\n touchMove: function (e) {\n // 1.计算出用户拖动的距离\n this.currentX = e.touches[0].pageX;\n this.distance = this.currentX - this.startX;\n let currentPosition = -this.currentIndex * this.totalWidth;\n let moveDistance = this.distance + currentPosition;\n\n // 2.设置当前的位置\n this.setTransform(moveDistance);\n },\n\n touchEnd: function (e) {\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n // 1.获取移动的距离\n let currentMove = Math.abs(this.distance);\n\n // 2.判断最终的距离\n if (this.distance === 0) {\n return\n } else if (this.distance > 0 && currentMove > this.totalWidth * this.moveRatio) { // 右边移动超过0.5\n this.currentIndex--\n } else if (this.distance < 0 && currentMove > this.totalWidth * this.moveRatio) { // 向左移动超过0.5\n this.currentIndex++\n }\n\n // 3.移动到正确的位置\n this.scrollContent(-this.currentIndex * this.totalWidth);\n\n // 4.移动完成后重新开启定时器\n this.startTimer();\n },\n\n /**\n * 控制上一个, 下一个\n */\n previous: function () {\n this.changeItem(-1);\n },\n\n next: function () {\n this.changeItem(1);\n },\n\n changeItem: function (num) {\n // 1.移除定时器\n this.stopTimer();\n\n // 2.修改index和位置\n this.currentIndex += num;\n this.scrollContent(-this.currentIndex * this.totalWidth);\n\n // 3.添加定时器\n this.startTimer();\n }\n }\n\t}\n</script>\n\n<style scoped>\n #hy-swiper {\n overflow: hidden;\n position: relative;\n }\n\n .swiper {\n display: flex;\n }\n\n .indicator {\n display: flex;\n justify-content: center;\n position: absolute;\n width: 100%;\n bottom: 8px;\n }\n\n .indi-item {\n box-sizing: border-box;\n width: 8px;\n height: 8px;\n border-radius: 4px;\n background-color: #fff;\n line-height: 8px;\n text-align: center;\n font-size: 12px;\n margin: 0 5px;\n }\n\n .indi-item.active {\n background-color: rgba(212,62,46,1.0);\n }\n</style>\n"]}]} |