zoukankan      html  css  js  c++  java
  • vue制作幻灯片-左右移动

    组件中:

    <template>
    <div class="slide-show" @mouseover="clearInv" @mouseout="runInv">
    <div class="slide-img">
    <a :href="slidesList[nowindex].href">
    <transition name="slide-trans">
    <img v-if="isShow" :src="slidesList[nowindex].src" />
    </transition>

    <transition name="slide-trans-old">
    <img v-if="!isShow" :src="slidesList[nowindex].src" />
    </transition>
    </a>
    </div>

    <h2></h2>
    <ul class="slide-pages">
    <li @click="goto(prevIndex)">&lt;</li>
    <li v-for="(item,index) in slidesList" @click="goto(index)" :class="{on: index === nowindex }">{{index+1}}</li>
    <li @click="goto(nextIndex)">&gt;</li>
    </ul>
    </div>
    </template>

    <script>

    export default {
    props: {
    slidesList: {
    type: Array,
    default: []
    },
    time: {
    type: Number,
    default: 1000
    }
    },
    data () {
    return {
    nowindex: 0,
    isShow: true,
    }
    },
    computed: {
    prevIndex () {
    if(this.nowindex === 0){
    return this.slidesList.length - 1
    }else{
    return this.nowindex - 1
    }
    },
    nextIndex () {
    if(this.nowindex === this.slidesList.length-1){
    return 0
    }else{
    return this.nowindex + 1
    }
    }
    },
    methods: {
    goto (index) {
    this.isShow = false
    setTimeout(() => {
    this.isShow = true
    this.nowindex = index;
    },10)
    },
    runInv () {
    this.clr=setInterval(() => {
    this.goto(this.nextIndex);
    }, this.time)
    },
    clearInv(){
    clearInterval(this.clr)
    }
    },
    mounted () {
    this.runInv ()
    }
    }
    </script>

    <style>
    .slide-trans-enter-active{
    transition: all .5s;
    }
    .slide-trans-enter{
    transform: translateX(900px);
    }
    .slide-trans-old-leave-active{
    transition: all .5s;
    transform: translateX(-900px);
    }
    .slide-show {
    position: relative;
    margin: 15px 15px 15px 0;
    900px;
    height: 500px;
    overflow: hidden;
    }
    .slide-show h2 {
    position: absolute;
    100%;
    height: 100%;
    color: #fff;
    background: #000;
    opacity: .5;
    bottom: 0;
    height: 30px;
    text-align: left;
    padding-left: 15px;
    }
    .slide-img {
    100%;
    }

    .slide-img img {
    100%;
    position: absolute;
    top: 0;
    }

    .slide-pages {
    position: absolute;
    bottom: 10px;
    right: 15px;
    }

    .slide-pages li {
    display: inline-block;
    padding: 0 10px;
    cursor: pointer;
    color: #fff;
    }

    .slide-pages li.on {
    text-decoration: underline;
    }
    </style>

    页面中:

    <sild-show :slidesList= "slides" :time="slideSpeed"></sild-show>

    import sildShow from "../components/sildeShow"
    export default{
      components:{
      sildShow
      },

      data () {
      return {
        slides: [
        {
          src: require('../assets/slideShow/pic1.jpg'),
          title: 'xxx1',
          href: 'detail/analysis'
        },
        {
          src: require('../assets/slideShow/pic2.jpg'),
          title: 'xxx2',
          href: 'detail/count'
        },
        {
          src: require('../assets/slideShow/pic3.jpg'),
          title: 'xxx3',
          href: 'detail/publish'
        },
        {
          src: require('../assets/slideShow/pic4.jpg'),
          title: 'xxx4',
          href: 'detail/forecast'
        }
        ],
        slideSpeed: 2000,

      }

      }

    }

  • 相关阅读:
    科普文,无论在哪选配计算机,都要懂得常识 (任务5)
    任务5 配机网站关注热点解读
    科普文,解析品牌机的配置特点,选配计算机可以这么做(任务4)
    任务4 解析品牌机配置
    立足于应用需求,看到整体性能,评价计算机的性能(任务3)
    科普文,分享计算机优化的套路,停掉不需要的进程(任务3)
    任务3对电脑进行评价,硬件健康,性能测试, WINDOWS体验指数
    任务2认知计算机系统(计算机系统是一个生态系统,分为硬件系统和软件系统,互为支撑)
    数据库程序接口——JDBC——API解读第一篇——建立连接的核心对象
    数据库程序接口——JDBC——API解读第二篇——执行SQL的核心对象
  • 原文地址:https://www.cnblogs.com/seven077/p/7813312.html
Copyright © 2011-2022 走看看