1. <script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
  2. <style>
  3. *{margin: 0;padding: 0}
  4. .container{
  5. position: relative;
  6. width: 600px;
  7. margin-left: auto;
  8. margin-right: auto;
  9. }
  10. .handle{
  11. width: 120px;
  12. height: 200px;
  13. position: absolute;
  14. left: 37%;
  15. transform: rotate(-30deg);
  16. transform-origin: 30px 30px; /* 旋转中心点 */
  17. }
  18. .pan{
  19. width: 300px;
  20. height: 300px;
  21. position: absolute;
  22. top: 130px;
  23. left: 125px;
  24. }
  25. @keyframes move{
  26. 0%{
  27. transform:rotate(-30deg)
  28. }
  29. 100%{
  30. transform: rotate(0deg)
  31. }
  32. }
  33. @keyframes unmove{
  34. 0%{
  35. transform: rotate(0deg)
  36. }
  37. 100%{
  38. transform: rotate(-30deg)
  39. }
  40. }
  41. /* animation-fill-mode:forwards;
  42. backwards:动画结束时会回到开始位置
  43. forwards:动画会在结束位置停止
  44. */
  45. .move{
  46. animation: move 2s forwards;
  47. }
  48. .unmove{
  49. animation: unmove 2s forwards;
  50. }
  51. </style>
  1. <div class="container">
  2. <!-- {{isPlay}} -->
  3. <img @click="handleClick" class="pan" src="images/pan.png" alt="">
  4. <img :class="[isPlay?'move':'unmove','handle' ]" src="images/shou.png" alt="">
  5. </div>
  6. <script>
  7. new Vue({
  8. el:".container",
  9. data:{
  10. isPlay:false
  11. },
  12. methods:{
  13. handleClick(){
  14. this.isPlay=!this.isPlay;
  15. }
  16. }
  17. })
  18. </script>

课件地址:

https://gitee.com/wangsiman/wuhannotebook/blob/master/javascript/js-day13/04vue-music.html