前端学习之百叶窗效果

1. 结果展示

请添加图片描述
原教程:https://www.bilibili.com/video/BV1iK4y1s7Db?spm_id_from=333.999.0.0&vd_source=36b18f2d7c5333a81747c014397b7f36

这一次我将代码改了一下通过vue+js实现,当鼠标移动到页面时就播放视频,这里我将图片改成了视频的方式实现,这里可以使用 gif 等实现方式,这里看起来比较丑,使用图片就比较好看了,有些bug也没有调整比如,暂停后需要显示封面等。演示地址:http://150.158.10.192/web

<template>
  <div class="box">
    <ul class="box_ul">
      <li v-for="(p,index) in paths" :key="index">
        <video :id="'video-'+index" muted="muted"
               x5-video-orientation="portraint"
               :poster="require('@/assets/video/' + p.poster)"
               @mouseover="play(index)"
               @mouseleave="stop(index)"
               :src="require('@/assets/video/' + p.video)"></video>
        <!--<img :src="require('@/assets/imgs/index/' + p.img)">-->
        <div class="text">{{ p.desc }}</div>
      </li>
    </ul>
  </div>

</template>

<script>
export default {
  name: 'Index',
  data() {
    return {
      paths: [
        {
          path: "/shuffling",
          desc: '会发光的Button',
          video: '发光的Button.mp4',
          poster: '发光的button封面.png'
        }, {
          path: "/button",
          desc: '会发光的Button',
          video: '发光的Button.mp4',
          poster: '发光的button封面.png'
        }, {
          path: "/button",
          desc: '会发光的Button',
          video: '发光的Button.mp4',
          poster: '发光的button封面.png'
        }, {
          path: "/button",
          desc: '会发光的Button',
          video: '发光的Button.mp4',
          poster: '发光的button封面.png'
        }, {
          path: "/button",
          desc: '会发光的Button',
          video: '发光的Button.mp4',
          poster: '发光的button封面.png'
        }
      ]
    }
  },
  methods: {
    play(index) {
      let media = document.getElementById("video-"+index)
      if (media) {
      //开始播放
        media.play()
      }
    },
    stop(index) {
      let media = document.getElementById("video-"+index)
      if (media) {
      //暂停播放,将实现设置从头开始
        media.pause()
        media.currentTime = 0
      }
    }
  }
}
</script>

<style>

body {
  background-color: #453a94;
  height: 100vh;
  width: 100%;
}

li {
  list-style: none;
}

.box_ul {
  width: 1000px;
  height: 320px;
  margin: 200px auto;
  overflow: hidden;
  transition: all .3s;
}

.box_ul li {
  float: left;
  height: 320px;
  width: 200px;
  position: relative;
  transition: all .3s;
}

/*设置字体的位置以及样式*/
.box_ul li .text {
  position: absolute; /*使用绝对定位,找到最近的父级也就是 li*/
  left: 0;
  bottom: 0;
  font-size: 10px;
  color: #ffffff;
  width: 100%;
  height: 30px;
  text-align: center;
  line-height: 30px;
  background-color: rgba(0,0,0,.3); /*可以是背景颜色编程渐变趋向于透明*/
}

.box_ul:hover li {
  width: 90px;  /*设置90px,因为box整体为1000px,移到li上变成640px,剩余360px,其他4张图平均下来就为90px,否则最后一张图的显示会有问题*/
}

/*移动到 li上时,将其变为640px*/
.box_ul li:hover {
  width: 640px;
}

</style>


  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值