zoukankan      html  css  js  c++  java
  • 轮播图

    VUE轮播实例  

    https://segmentfault.com/a/1190000008828755       //VUE过度实现轮播图  
    http://www.jq22.com/jquery-info15947    //VUE轮播图插件

     参考代码:

    <template>
          <div class="carousel-wrap" id="carousel">
                <transition-group tag="ul" class='slide-ul' name="list">
                      <li v-for="(list,index) in slideList" :key="index" v-show="index===currentIndex" @mouseenter="stop" @mouseleave="go">
                            <a> <img :src="list.image"></a>
                      </li>
                </transition-group> 
                <div class="carousel-items">
                      <span v-for="(item,index) in slideList.length" :class="{'active':index===currentIndex}" @mouseover="change(index)"></span>
                </div>
          </div>
    </template>
     
    <script>
    export default {
          data () {
                return {
                      slideList: [
                            { 
                                "image": "../../static/IMG/PublicImg/index2.jpg"
                            },
                            { 
                                "image": "../../static/IMG/PublicImg/index1.jpg"
                            }
                        ],
                        currentIndex: 0,
                        timer: ''
                }
          },
          methods: {
                go() {
                    this.timer = setInterval(() => {
                        this.autoPlay()
                    }, 3000)
                },
                stop() {
                    clearInterval(this.timer)
                    this.timer = null
                },
                change(index) {
                    this.currentIndex = index
                },
                autoPlay() {
                    this.currentIndex++
                    if (this.currentIndex > this.slideList.length - 1) {
                        this.currentIndex = 0
                    }
                }
          },
          created() {
              //在DOM加载完成后,下个tick中开始轮播
              this.$nextTick(() => {
                  // this.timer = setInterval(() => {
                  //     this.autoPlay()
                  // }, 2000)
              })
          }
    }
    </script>
    
    <style>
    ul{
          list-style:none;
          padding: 0;
          margin: 0;
    }
    .carousel-wrap {
      position: relative;
      height: 500px;
       100%;
      overflow: hidden; 
      background-color: #fff;
    } 
    .slide-ul {
           100%;
          height: 100%;
          padding: 0;
          li {
                position: absolute;
                 100%;
                height: 100%;
                img {
                       100%;
                      height: 100%;
                }
          }
    }
    .carousel-items {
      position: absolute;
      z-index: 10;
      top: 380px;
       100%;
      margin: 0 auto;
      text-align: center;
      font-size: 0;  
    }
    .carousel-items .active {
          background-color: #02ECE3;
    }
    .carousel-items span {
        display: inline-block;
        height: 6px;
         30px;
        margin: 0 3px;
        background-color: #b2b2b2;
        cursor: pointer;
      }
    </style>
  • 相关阅读:
    实现多页签切换效果
    CSS样式display:none和visibility:hidden的区别
    canvas主要属性和方法
    Web前端的35个jQuery小技巧
    div+css3实现的小丸子和爷爷
    Jquery实现手机上下滑屏滑动的特效代码
    使用phantomjs生成网站快照
    VSCode配置Go language tools
    TypeScript中慎用forEach
    win8开发之数据绑定控件Gridview以分组及不同项模板的形式呈现数据
  • 原文地址:https://www.cnblogs.com/miaoyiyan/p/9540880.html
Copyright © 2011-2022 走看看