vue 设置整屏背景色 音乐播放

阳光穿透心脏的1/2处 2023-06-25 08:07 148阅读 0赞

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zODQwNDg5OQ_size_16_color_FFFFFF_t_70

  1. <template>
  2. <div class="gif">
  3. <!-- <p class="count">{
  4. {count}}</p> -->
  5. <div @click="close" class="close">
  6. <i class="iconfont icon-shengyin1" v-show="show_iocn"></i>
  7. <i class="iconfont icon-shengyinguanbi" v-show="show_iocn2"></i>
  8. </div>
  9. <div class="animation">
  10. <img src="../assets/img/5.gif" alt="">
  11. </div>
  12. <!-- 音乐默认播放 -->
  13. <audio id='music' :src="ling" class="media-audio" ref="MusicPlay" autoplay></audio>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. name: 'animation',
  19. data () {
  20. return {
  21. ling:require("../assets/ling.mp3"), //mp3文件
  22. show_iocn:true, //开图标
  23. show_iocn2:false, //关图标
  24. }
  25. },
  26. methods: {
  27. //关闭音乐
  28. close() {
  29. var audio = document.getElementById('music');
  30. if (audio.paused) {
  31. audio.play(); // 播放
  32. this.show_iocn=true;
  33. this.show_iocn2 = false;
  34. } else {
  35. this.show_iocn=false;
  36. this.show_iocn2 = true;
  37. audio.pause();// 暂停
  38. }
  39. }
  40. },
  41. //vue设置整屏背景色
  42. mounted() {
  43. document.querySelector('body').setAttribute('style', 'background-color:#F5B754')
  44. var _this = this
  45. setTimeout(function(){
  46. _this.$router.push('/studentId');
  47. },8200)
  48. },
  49. //页面跳转去掉背景色
  50. beforeDestroy() {
  51. document.querySelector('body').removeAttribute('style')
  52. }
  53. }
  54. </script>
  55. <style scoped>
  56. .animation{
  57. width: 100%;
  58. position: absolute;
  59. left: 50%;
  60. top: 50%;
  61. transform:translate(-50%,-50%);
  62. }
  63. .animation img{
  64. width: 100%;
  65. height: 10rem;
  66. }
  67. .close{
  68. float: right;
  69. margin-right: .5rem;
  70. margin-top:.5rem;
  71. }
  72. .close i{
  73. font-size: .7rem;
  74. color: #fff;
  75. }
  76. </style>

发表评论

表情:
评论列表 (有 0 条评论,148人围观)

还没有评论,来说两句吧...

相关阅读