vue实现仿淘宝详情页商品轮播效果
1、使用组件:
https://github.com/antoniandre/vueper-slides
demo:https://antoniandre.github.io/vueper-slides/
2、安装组件
C/C++ Code复制内容到剪贴板
- npm install vueperslides
vue3
C/C++ Code复制内容到剪贴板
- npm install vueperslides@next
完整代码:
使用:
XML/HTML Code复制内容到剪贴板
- <album bigImgHeight="300px" smallImgHeight="58px" class="album"></album>
- <script>
- import album from './components/album.vue'
- export default {
- components: {
- album
- },
- ...
album组件
XML/HTML Code复制内容到剪贴板
- <template>
- <div class="album">
- <vueper-slides
- ref="vueperslides1"
- :touchable="false"
- fade
- :autoplay="false"
- :bullets="false"
- @slide="$refs.vueperslides2.goToSlide($event.currentSlide.index, { emit: false })"
- :fixed-height="bigImgHeight">
- <vueper-slide
- v-for="(slide, i) in slides"
- :key="i"
- :image="slide.image">
- </vueper-slide>
- </vueper-slides>
- <vueper-slides
- class="no-shadow thumbnails"
- ref="vueperslides2"
- @slide="$refs.vueperslides1.goToSlide($event.currentSlide.index, { emit: false })"
- :visible-slides="slides.length"
- :fixed-height="smallImgHeight"
- :bullets="false"
- :touchable="false"
- :gap="2.5"
- :arrows="false">
- <vueper-slide
- v-for="(slide, i) in slides"
- :key="i"
- :image="slide.image"
- @click.native="$refs.vueperslides2.goToSlide(i)">
- </vueper-slide>
- </vueper-slides>
- </div>
- </template>
- <script>
- import { VueperSlides, VueperSlide } from 'vueperslides'
- import 'vueperslides/dist/vueperslides.css'
- export default {
- props: {
- bigImgHeight: {
- type: String,
- default () {
- return '400px'
- }
- },
- smallImgHeight: {
- type: String,
- default () {
- return '75px'
- }
- }
- },
- components: {
- VueperSlides,
- VueperSlide
- },
- data () {
- return {
- slides: [
- {
- image: require('@/assets/frontend/banner/el-teide-volcano-spain.jpeg')
- },
- {
- image: require('@/assets/frontend/banner/chernobyl-ukraine.jpeg')
- },
- {
- image: require('@/assets/frontend/banner/crater-lake-oregon-usa.jpeg')
- },
- {
- image: require('@/assets/frontend/banner/el-teide-volcano-spain.jpeg')
- }
- ]
- }
- },
- mounted () {
- console.log('mounted?')
- }
- }
- </script>
- <style lang="less" scoped>
- .album{
- width: 100%;
- .thumbnails {
- margin: auto;
- max-width: 300px;
- margin-top: 20px;
- }
- .thumbnails .vueperslide {
- box-sizing: border-box;
- border: 1px solid #fff;
- transition: 0.3s ease-in-out;
- opacity: 0.7;
- cursor: pointer;
- }
- .thumbnails .vueperslide--active {
- box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
- opacity: 1;
- border-color: #000;
- }
- }
- </style>