A special Avatar spoof Effect Based on jquery and css3, jquerycss3

Source: Internet
Author: User

A special Avatar spoof Effect Based on jquery and css3, jquerycss3

Today we will share with you a special Avatar spoof Effect Based on jquery and css3. In this example, a avatar is dancing on the screen, and there are cute hats in the Avatar. You can click the button below to switch between different hats for the Avatar. As follows:

Download Online Preview source code

Implementation code.

Html code:

Html code
  1. <Div class = "wwiaftm-container">
  2. <Div class = "base wwiaftm">
  3. <Div class = "body-1 wwiaftm">
  4. <Div class = "body-2 wwiaftm">
  5. <Div class = "hat wwiaftm" style = "background-image: url(Mini_Sombrero.png)">
  6. </Div>
  7. <Div class = "head wwiaftm">
  8. <Div class = "profile">
  9. </Div>
  10. </Div>
  11. <Div class = "wwiaftm arm-1 left">
  12. <Div class = "wwiaftm arm-2 left">
  13. <Div class = "wwiaftm fingers">
  14. </Div>
  15. </Div>
  16. </Div>
  17. <Div class = "wwiaftm arm-1 right">
  18. <Div class = "wwiaftm arm-2 right">
  19. <Div class = "wwiaftm fingers">
  20. </Div>
  21. </Div>
  22. </Div>
  23. </Div>
  24. </Div>
  25. </Div>
  26. </Div>
  27. <Div class = "switch-container">
  28. <Button id = "hat-switch">
  29. Hat Me! </Button>
  30. </Div>
  31. <Script src = 'jquery. min. js'> </script>
  32. <Script> var hats = Array (
  33. 'Mini_Sombrero.png ', 'med.png ',
  34. 'Svg.med.png ',
  35. 'Cartoon-cowboy-8.gif ',
  36. '1313955-witch-hat-002_92007.gif ',
  37. 'Hat_mario_101401.jpg ',
  38. 'Vector-hat-design1.jpg'
  39. );
  40. $ ('# Hat-switch'). on ('click', function (e ){
  41. E. preventDefault ();
  42. Var hat = hats [Math. floor (Math. random () * hats. length)];
  43. Certificate ('.hat').css ('background-image', 'url ('+ hat + ')');
  44. });
  45. // @ SourceURL = pen. js
  46. </Script>

Css3 code:

Html code
  1. . Wwiaftm-container {
  2. Position: relative;
  3. Width: 200px;
  4. Height: 275px;
  5. Margin: auto;
  6. Padding-top: 100px;
  7. }
  8. . Profile {
  9. Border-radius: 100px;
  10. Overflow: hidden;
  11. }
  12. . Wwiaftm {
  13. Background: #48e0a4;
  14. Position: absolute;
  15. Margin: auto;
  16. Border-radius: 25%;
  17. }
  18. . Body-1 {
  19. Background-repeat: no-repeat;
  20. Background-position: center;
  21. Background-size: 70%;
  22. }
  23. . Base {
  24. Width: 60px;
  25. Height: 80px;
  26. Bottom: 0;
  27. Left: 0;
  28. Right: 0;
  29. }
  30. . Hat {
  31. Top:-120px;
  32. Height: 80px;
  33. Width: 100px;
  34. -Webkit-transform-origin: 50% 100%;
  35. Transform-origin: 50% 100%;
  36. -Webkit-transform: rotate3d (0, 0, 1, 0deg );
  37. Transform: rotate3d (0, 0, 1, 0deg );
  38. Background-repeat: no-repeat;
  39. Background-position: center;
  40. Transparent;
  41. Background-size: 100%;
  42. Z-index: 10! Important;
  43. }
  44. . Body-1,. body-2,. head {
  45. Top:-60px;
  46. Height: 80px;
  47. Width: 60px;
  48. -Webkit-transform-origin: 50% 100%;
  49. Transform-origin: 50% 100%;
  50. -Webkit-transform: rotate3d (0, 0, 1, 0deg );
  51. Transform: rotate3d (0, 0, 1, 0deg );
  52. }
  53. . Body-1 {
  54. -Webkit-animation: flail 4S linear infinite;
  55. Animation: flail 4S linear infinite;
  56. }
  57. . Body-2 {
  58. -Webkit-animation: flail 3 s linear infinite;
  59. Animation: flail 3 s linear infinite;
  60. }
  61. . Head,. hat {
  62. -Webkit-animation: flail 2 s linear infinite;
  63. Animation: flail 2 s linear infinite;
  64. Z-index: 1;
  65. }
  66. . Head. eye,. head. mouth {
  67. Height: 20%;
  68. Width: 15%;
  69. Background: black;
  70. Position: absolute;
  71. Top: 25%;
  72. }
  73. . Head. eye. right {
  74. Right: 20%;
  75. }
  76. . Head. eye. left {
  77. Left: 20%;
  78. }
  79. . Head. mouth {
  80. Width: 70%;
  81. Top: 60%;
  82. Height: 5%;
  83. Left: 0;
  84. Right: 0;
  85. Margin: auto;
  86. }
  87. . Arm-1,. arm-2 {
  88. Position: absolute;
  89. Width: 50px;
  90. Height: 20px;
  91. Right: 90%;
  92. Top: 25%;
  93. -Webkit-animation: flail 1 s linear infinite;
  94. Animation: flail 1 s linear infinite;
  95. -Webkit-transform-origin: 100% 50%;
  96. Transform-origin: 100% 50%;
  97. }
  98. Arm-1.right,. arm-2.right {
  99. Left: 90%;
  100. -Webkit-transform-origin: 0% 50%;
  101. Transform-origin: 0% 50%;
  102. }
  103. . Arm-1. arm-2 {
  104. -Webkit-animation: flail. 5 s linear infinite;
  105. Animation: flail. 5 s linear infinite;
  106. Right: 80%;
  107. Top: auto;
  108. }
  109. . Arm-1. arm-2.right {
  110. Left: 80%;
  111. Right: auto;
  112. }
  113. @-Webkit-keyframes flail {
  114. 0% {
  115. -Webkit-transform: rotate3d (0, 0, 1, 0deg );
  116. }
  117. 25% {
  118. -Webkit-transform: rotate3d (0, 0, 1, 50deg );
  119. }
  120. 50% {
  121. -Webkit-transform: rotate3d (0, 0, 1, 0deg );
  122. }
  123. 75% {
  124. -Webkit-transform: rotate3d (0, 0, 1,-50deg );
  125. }
  126. 100% {
  127. -Webkit-transform: rotate3d (0, 0, 1, 0deg );
  128. }
  129. }
  130. @ Keyframes flail {
  131. 0% {
  132. Transform: rotate3d (0, 0, 1, 0deg );
  133. }
  134. 25% {
  135. Transform: rotate3d (0, 0, 1, 50deg );
  136. }
  137. 50% {
  138. Transform: rotate3d (0, 0, 1, 0deg );
  139. }
  140. 75% {
  141. Transform: rotate3d (0, 0, 1,-50deg );
  142. }
  143. 100% {
  144. Transform: rotate3d (0, 0, 1, 0deg );
  145. }
  146. }
  147. . Switch-container {
  148. Text-align: center;
  149. Margin-top: 25px;
  150. }
  151. # Hat-switch {
  152. Text-align: center;
  153. Font-size: 24px;
  154. Cursor: pointer;
  155. }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.