• vue做的一个一点就转的转盘(音乐磁盘),点击停止时会在几秒内缓慢停止,再次点击按钮可以再次旋转,


    先看效果:

    代码:主要部分我会红线画出来

    css:部分:

    源码:

    vue部分:

    1. <template>
    2. <div class="song-lyric">
    3. <div>
    4. <div class="type">
    5. <div class="right">
    6. <div class="right-center" :class="{ 'rotates': isplay }">
    7. <div>
    8. <img src="https://imagesone.oss-cn-beijing.aliyuncs.com/imagebishe/player_bar.png"
    9. class="right-top" :class="{rotated: isplay}">
    10. </div>
    11. <div>
    12. <img src="https://imagesone.oss-cn-beijing.aliyuncs.com/imagebishe/disc.png"
    13. class="tight-bottm" :style="{ transform: 'rotate(' + rotationAngle + 'deg)' }">
    14. </div>
    15. </div>
    16. </div>
    17. <div class="lyric-title">
    18. <!-- 有歌词 -->
    19. <!-- <el-input v-model="input" placeholder="请输入内"></el-input>
    20. <el-input v-model="input" placeholder="差不多"></el-input> -->
    21. <ul class="has-lyric" v-if="lyr.length" key="index">
    22. <li v-for="(item,index) in lyr" v-bind:key="index">
    23. {{item[1]}}
    24. </li>
    25. </ul>
    26. <!-- 没有歌词 -->
    27. <div v-else class="no-lyric" key="no-lyric">
    28. <span>暂无歌词</span>
    29. </div>
    30. </div>
    31. </div>
    32. </div>
    33. </div>
    34. </template>
    35. <script>
    36. import {
    37. mixin
    38. } from '../mixins';
    39. import {
    40. mapGetters
    41. } from 'vuex';
    42. export default {
    43. name: 'lyric',
    44. mixins: [mixin],
    45. data() {
    46. return {
    47. // input: '',
    48. lyr: [], //当前歌曲的歌词
    49. isplay: undefined, //获取歌曲开关状态
    50. rotationAngle: 0 // 记录盒子当前的旋转角度
    51. }
    52. },
    53. computed: {
    54. ...mapGetters([
    55. 'curTime', //当前歌曲播放到的位置
    56. 'id', //当前播放的歌曲id
    57. 'lyric', //歌词
    58. 'listIndex', //当前歌曲在歌单中的位置
    59. 'listOfSongs', //当前歌单列表
    60. 'isPlay' //播放状态
    61. ])
    62. },
    63. created() {
    64. this.isplay = this.isPlay//获取开关
    65. console.log('data', this.isplay);//获取点击图片进去歌词页面的开关状态
    66. this.lyr = this.lyric;
    67. this.rotateBox();
    68. console.log('this.lyr', this.lyr)
    69. console.log('this.mapGetters', this.mapGetters)
    70. },
    71. watch: {
    72. isPlay() {
    73. this.isplay = this.isPlay
    74. console.log('data', this.isplay);
    75. this.rotateBox();
    76. },
    77. id: function() {
    78. this.lyr = this.parseLyric(this.listOfSongs[this.listIndex].lyric)
    79. },
    80. curTime: function() {
    81. if (this.lyr.length > 0) {
    82. for (let i = 0; i < this.lyr.length; i++) {
    83. if (this.curTime >= this.lyr[i][0]) {
    84. for (let j = 0; j < this.lyr.length; j++) {
    85. document.querySelectorAll('.has-lyric li')[j].style.color = '#ffffff';
    86. document.querySelectorAll('.has-lyric li')[j].style.fontSize = '15px';
    87. }
    88. if (i >= 0) {
    89. document.querySelectorAll('.has-lyric li')[i].style.color = '#95d2f6';
    90. document.querySelectorAll('.has-lyric li')[i].style.fontSize = '25px';
    91. }
    92. }
    93. }
    94. }
    95. }
    96. },
    97. methods:{
    98. rotateBox(){
    99. if(this.isplay){
    100. this.rotationAngle +=1;
    101. // if(this.rotationAngle >= 360){
    102. // this.rotationAngle = this.rotationAngle % 360;
    103. // }
    104. setTimeout(this.rotateBox, 20);
    105. // console.log('this.rotateBox',this.rotationAngle)
    106. }
    107. }
    108. }
    109. }
    110. </script>
    111. <style lang="scss" scoped>
    112. @import '../assets/css/lyric.scss';
    113. </style>

    css部分:

    1. @import "var.scss";
    2. .song-lyric {
    3. // margin: auto;
    4. // margin-top: $header-height + 20px;
    5. width: 100%;
    6. height: 100%;
    7. // background-color: $color-white;
    8. border-radius: 12px;
    9. display: block;
    10. background-color: rgb(167, 167, 167);
    11. // padding: 0 20px 50px 20px;
    12. // background-color: rgba(0,0,0,.55);
    13. font-family: $font-family;
    14. // background-size: cover;
    15. // filter: blur(30px);
    16. z-index: 1;
    17. .lyric-title {
    18. text-align: center;
    19. width: 50%;
    20. height: 100vh;
    21. overflow-y: scroll;
    22. line-height: 60px;
    23. border-bottom: 2px solid $color-black;
    24. margin-top: 50px;
    25. // background: rgba(21, 21, 21, 0.6);
    26. background-color: rgba(0,0,0,.65);
    27. z-index: 2;
    28. }
    29. .type{
    30. display: flex;
    31. text-align: center;
    32. width: 100%;
    33. height: 100vh;
    34. overflow: hidden;
    35. line-height: 60px;
    36. border-bottom: 2px solid $color-black;
    37. z-index: 2;
    38. }
    39. .right{
    40. text-align: center;
    41. width: 50%;
    42. height: 100vh;
    43. overflow: hidden;
    44. line-height: 60px;
    45. border-bottom: 2px solid $color-black;
    46. margin-top: 50px;
    47. display: flex;
    48. justify-content: center;
    49. align-items: center;
    50. flex-direction: column;
    51. flex-wrap: wrap;
    52. // background: rgba(21, 21, 21, 0.6);
    53. background-color: rgba(0,0,0,.65);
    54. // backdrop-filter: blur(4px);
    55. // box-shadow: inset 0px 1px 6px rgba(255,255,255,0.6), 2px 2px 15px rgba(0,0,0,0.5);
    56. z-index: 2;
    57. }
    58. .right-top{ //指针
    59. position: absolute;
    60. z-index: 1;
    61. width: auto;
    62. left:45%;
    63. top:117px;
    64. height:200px;
    65. transition: transform 0.7s linear; transform: rotate(-30deg) translate(35px , -10px);
    66. }
    67. .rotated {
    68. transform: rotate(0deg);
    69. }
    70. .right-center{
    71. position: relative;
    72. width: 600px;
    73. height: 1000px;
    74. // background-color: rgb(206, 198, 198);
    75. }
    76. .has-lyric {
    77. font-size: 18px;
    78. width: 100%;
    79. min-height: 100%;
    80. text-align: center;
    81. padding-top: 120px;
    82. li {
    83. width: 100%;
    84. height: 40px;
    85. line-height: 40px;
    86. }
    87. }
    88. .no-lyric {
    89. // margin: 200px 0;
    90. padding: 200px 0 0 0;
    91. width: 100%;
    92. text-align: center;
    93. span {
    94. font-size: 18px;
    95. text-align: center;
    96. }
    97. }
    98. }
    99. .lyric-fade-enter,
    100. .lyric-fade-leave-to {
    101. transform: translateX(30px);
    102. opacity: 0;
    103. }
    104. .lyric-fade-enter-active,
    105. .lyric-fade-leave-active {
    106. transition: all 0.3s ease;
    107. }
    108. .tight-bottm{ //圆
    109. position: absolute;
    110. top:225px;
    111. width: 400px;
    112. left:18%;
    113. height:400px;
    114. border-radius: 50%;
    115. transition: transform 0.7s linear;
    116. }
    117. .active {
    118. animation: none !important;
    119. // animation: spin 5s linear infinite;
    120. }
    121. // @keyframes spin {
    122. // 100% {
    123. // transform: rotate(360deg);
    124. // }
    125. // }

  • 相关阅读:
    ShardingSphere-proxy-5.0.0容量范围分片的实现(五)
    答疑(蓝桥杯)
    【PyQt5】教你如何使用designer制作可上下移动的界面
    《SpringBoot篇》11.JPA常用注解只需一个表
    linux下安装python3.8(有坑)
    【软件部署】Linux源码安装Jenkins
    9.用户权限相关命令
    python AssertionError: Torch not compiled with CUDA enabled
    【模型压缩】模型剪枝模块
    基于隐私保护计算的金融科技创新探索
  • 原文地址:https://blog.csdn.net/m0_65069237/article/details/134351006