当前位置:   article > 正文

小demo:微信拍一拍功能实现_微信拍一拍怎么做前端

微信拍一拍怎么做前端

使用CSS3的动画特效和JS

双击后头像摇动及显示拍一拍

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <style>
  7. .containor{
  8. width: 550px;
  9. height: 500px;
  10. border: 1px solid #cccc;
  11. position: relative;
  12. background-color: #ccc;
  13. }
  14. .containor>img{
  15. width: 50px;
  16. height: 50px;
  17. border-radius: 8px;
  18. }
  19. .containor>p{
  20. border: 1px soli #ccc;
  21. background-color: white;
  22. display: inline-block;
  23. border-radius: 5px;
  24. color:black;
  25. padding: 5px;
  26. font-size: 14px;
  27. }
  28. .containor>img:nth-child(1){
  29. position: absolute;
  30. left: 10px;
  31. top:20px;
  32. }
  33. .containor>img:nth-child(2){
  34. position: absolute;
  35. right: 10px;
  36. top:100px;
  37. }
  38. .containor .one{
  39. position: absolute;
  40. top:18px;
  41. left: 70px;
  42. }
  43. .containor .two{
  44. position: absolute;
  45. top:97px;
  46. right: 70px;
  47. }
  48. .containor .hePad{
  49. display: none;
  50. position: absolute;
  51. top:150px;
  52. left: 200px;
  53. background-color: darkgrey;
  54. opacity: 0.4;
  55. }
  56. .containor .mePad{
  57. display: none;
  58. position: absolute;
  59. top:150px;
  60. left: 200px;
  61. background-color: darkgrey;
  62. opacity: 0.4;
  63. }
  64. @keyframes bePad{
  65. 0% {
  66. transform: rotate(0deg);
  67. }
  68. 20% {
  69. transform: rotate(20deg);
  70. }
  71. 40% {
  72. transform: rotate(-20deg);
  73. }
  74. 60% {
  75. transform: rotate(20deg);
  76. }
  77. 80% {
  78. transform: rotate(-20deg);
  79. }
  80. 100% {
  81. transform: rotate(0deg);
  82. }
  83. }
  84. @-webkit-@-webkit-keyframes bePad{ /* Safari and Chrome */
  85. 0% {
  86. transform: rotate(0deg);
  87. }
  88. 20% {
  89. transform: rotate(20deg);
  90. }
  91. 40% {
  92. transform: rotate(-20deg);
  93. }
  94. 60% {
  95. transform: rotate(20deg);
  96. }
  97. 80% {
  98. transform: rotate(-20deg);
  99. }
  100. 100% {
  101. transform: rotate(0deg);
  102. }
  103. }
  104. .containor .he{
  105. transform-origin: bottom;
  106. }
  107. .containor .me{
  108. transform-origin: bottom;
  109. }
  110. </style>
  111. <script>
  112. window.onload=function(){
  113. var he=document.querySelector(".he");
  114. var me=document.querySelector(".me");
  115. var hePad=document.querySelector(".hePad");
  116. var mePad=document.querySelector(".mePad");
  117. he.ondblclick=function(){
  118. this.style.animation=" bePad 0.5s ";
  119. hePad.style.display="block";
  120. setTimeout(()=>{
  121. this.style.animation=" ";
  122. hePad.style.display="";
  123. },2000);
  124. };
  125. me.ondblclick=function(){
  126. this.style.animation=" bePad 0.5s ";
  127. mePad.style.display="block";
  128. setTimeout(()=>{
  129. this.style.animation=" ";
  130. mePad.style.display="";
  131. },2000);
  132. }
  133. };
  134. </script>
  135. </head>
  136. <body>
  137. <div class="containor">
  138. <img src="./two.jpg" alt="" class="he">
  139. <img src="./one.jpg" alt="" class="me">
  140. <p class="one">*********************</p>
  141. <p class="two">嘿嘿嘿</p>
  142. <p class="hePad">榨汁机拍了拍汁</p>
  143. <p class="mePad">汁拍了拍榨汁机</p>
  144. </div>
  145. </body>
  146. </html>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/771357
推荐阅读
相关标签
  

闽ICP备14008679号