美文网首页
vue 旋转木马

vue 旋转木马

作者: 啊柒柒柒 | 来源:发表于2019-07-15 16:33 被阅读0次

以下是5张图片的配置, 图片减少或者增加都需要修改 config

<template>
  <div id="wrapper">
    <transition-group name="list" tag="ul" mode="out-in">
      <li v-for="(item, index) in piclist" :style="config[index]" :key="item.id">
        <img :src="item.url" style="width: 100%; height: 100%;">
      </li>
    </transition-group>
    <span id="arrLeft" class="prev" @click="turnleft">
      <Icon type="ios-arrow-back" class="icon"/>
    </span>
    <span id="arrRight" class="next" @click="turnright">
      <Icon type="ios-arrow-forward" class="icon"/>
    </span>
  </div>
</template>

<script>
export default {
  data() {
    return {
      piclist: [
        { id: '1', url: 'http://gss0.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/lvpics/w=1000/sign=9b38971c908fa0ec7fc7600d16a758ee/c8ea15ce36d3d5394fe85aec3b87e950342ab0cc.jpg' },
        { id: '2', url: 'http://pic40.nipic.com/20140331/9469669_142840860000_2.jpg'},
        { id: '3', url: 'http://gss0.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/lvpics/w=1000/sign=9b38971c908fa0ec7fc7600d16a758ee/c8ea15ce36d3d5394fe85aec3b87e950342ab0cc.jpg' },
        { id: '4', url: 'http://photocdn.sohu.com/20111207/Img328224894.jpg' },
        { id: '5', url: 'http://gss0.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/lvpics/w=1000/sign=9b38971c908fa0ec7fc7600d16a758ee/c8ea15ce36d3d5394fe85aec3b87e950342ab0cc.jpg' }
      ],
      //文件图片配置
      config: [
        {
          position: "absolute",
          width: "200px",
          height: "320px",
          top: "60px",
          left: "90px",
          opacity: 0.2,
          zIndex: 2,
          transition: "1s"
        },
        {
          position: "absolute",
          width: "200px",
          height: "380px",
          top: "30px",
          left: "140px",
          opacity: 0.8,
          zIndex: 2,
          transition: "1s"
        },
        {
          position: "absolute",
          width: "344px",
          height: "435px",
          top: "0px",
          left: "200px",
          opacity: 1,
          zIndex: 4,
          transition: "1s"
        },
        {
          position: "absolute",
          width: "200px",
          height: "380px",
          top: "30px",
          right: "140px",
          opacity: 0.8,
          zIndex: 2,
          transition: "1s"
        },
        {
          position: "absolute",
          width: "200px",
          height: "320px",
          top: "60px",
          right: "90px",
          opacity: 0.2,
          zIndex: 2,
          transition: "1s"
        }
      ],
      previous: 0,
      now: Date.now()
    };
  },
  methods: {
  //实现点击按钮切换的动画,设置时间参数防止多次点击
    turnleft: function() {
      this.now = Date.now();
      if (this.now - this.previous > 1000) {
        this.config.push(this.config.shift());
        this.previous = this.now;
      }
    },
    turnright: function() {
      this.now = Date.now();
      if (this.now - this.previous > 1000) {
        this.config.unshift(this.config.pop());
        this.previous = this.now;
      }
    }
  }
}
</script>

<style lang="less" scoped>
* {
  margin: 0;
  padding: 0;
}
#wrapper {
  margin: auto;
  height: 500px;
  width: 740px;
  margin: 0 auto;
  position: relative;
}
ul {
  list-style: none;
}
.prev,
.next {
  position: absolute;
  height: 40px;
  width: 40px;
  border-radius: 50%;
  top: 50%;
  margin-top: -56px;
  overflow: hidden;
  text-decoration: none;
  background: #000;
  z-index: 5;
  opacity: 0.12;
  text-align: center;
  line-height: 40px;
  cursor: pointer;
  .icon{
    color: #fff;
    font-size: 30px;
  }
}
.prev {
  left: 0;
}
.next {
  right: 0;
}
.picleft {
  width: 400;
  top: 20;
  left: 50;
  opacity: 0.2;
  z-index: 2;
}
.piccenter {
  width: 800;
  top: 100;
  left: 200;
  opacity: 1;
  z-index: 4;
}
.picright {
  width: 400;
  top: 20;
  left: 750;
  opacity: 0.2;
  z-index: 2;
}
</style>

相关文章

  • vue 旋转木马

    以下是5张图片的配置, 图片减少或者增加都需要修改 config

  • Vue css 旋转木马

    transform 属性应用 translate3d、rotate @keyframes 线性动画 运行效果 代码

  • 私房故事【4】:旋转木马的爱情

    旋转木马的传说:有人说旋转木马是见证两个相爱的人的爱情游戏,只要两个真心相爱的人同时坐在旋转木马上,木马就会载着他...

  • 2019-06-21

    ️旋转木马上

  • 。。

    想坐旋转木马

  • 《人生旋转木马》

    风来了, 沉寂的木马,旋转起来; 风走了, 木马依旧旋转着,借着惯性; 就好像风一直在。 风来,风去, 旋转木马,...

  • 《余情》游乐场

    木马很听话,在旋转着 听风声,在旋转木马上 小孩开心的笑着 几米之外的情侣犹豫着要不要坐上去 有人静静看着旋转木马...

  • 旋转木马

    不喜欢玩旋转木马,有人问为什么?刚开始我也不知道,后来才慢慢明白,因为它是个残忍的游戏,彼此追逐着,却永远追不上那...

  • 旋转木马

    追赶你的脚步, 触手可及, 却措手不及。 你的孤单背影, 挡住我的美丽风景, 或许不该在你身后, 那样便可不再和你错过。

  • 旋转木马

网友评论

      本文标题:vue 旋转木马

      本文链接:https://www.haomeiwen.com/subject/orankctx.html