1.jquery实现

  1. <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
  2. <style>
  3. * {
  4. margin: 0;
  5. padding: 0
  6. }
  7. .handle {
  8. position: absolute;
  9. left:37%;
  10. transform: rotate(-30deg);
  11. transform-origin: 60px 60px;
  12. }
  13. .container{
  14. position: relative;
  15. width:600px
  16. }
  17. .pan{
  18. position:absolute;
  19. top:200px;
  20. }
  21. @keyframes move{
  22. 0%{
  23. transform:rotate(-30deg)
  24. }
  25. 100%{
  26. transform:rotate(0deg)
  27. }
  28. }
  29. @keyframes unmove{
  30. 0%{
  31. transform:rotate(0deg)
  32. }
  33. 100%{
  34. transform:rotate(-30deg)
  35. }
  36. }
  37. .move{
  38. animation:move 2s forwards;
  39. }
  40. .unmove{
  41. animation:unmove 2s forwards;
  42. }
  43. </style>
  44. <body>
  45. <div class="container">
  46. <img class="pan" src="images/pan.png" alt="">
  47. <img class="handle" src="images/shou.png" alt="">
  48. </div>
  49. <script>
  50. var isPlay=false;
  51. $(".pan").click(function(){
  52. isPlay=!isPlay;
  53. console.log(isPlay)
  54. if(isPlay){
  55. $(".handle").addClass("move").removeClass("unmove")
  56. }else{
  57. $(".handle").removeClass("move").addClass("unmove")
  58. }
  59. })
  60. </script>

2.vue实现

  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>