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
- <Div class = "wwiaftm-container">
- <Div class = "base wwiaftm">
- <Div class = "body-1 wwiaftm">
- <Div class = "body-2 wwiaftm">
- <Div class = "hat wwiaftm" style = "background-image: url(Mini_Sombrero.png)">
- </Div>
- <Div class = "head wwiaftm">
- <Div class = "profile">
- </Div>
- </Div>
- <Div class = "wwiaftm arm-1 left">
- <Div class = "wwiaftm arm-2 left">
- <Div class = "wwiaftm fingers">
- </Div>
- </Div>
- </Div>
- <Div class = "wwiaftm arm-1 right">
- <Div class = "wwiaftm arm-2 right">
- <Div class = "wwiaftm fingers">
- </Div>
- </Div>
- </Div>
- </Div>
- </Div>
- </Div>
- </Div>
- <Div class = "switch-container">
- <Button id = "hat-switch">
- Hat Me! </Button>
- </Div>
- <Script src = 'jquery. min. js'> </script>
- <Script> var hats = Array (
- 'Mini_Sombrero.png ', 'med.png ',
- 'Svg.med.png ',
- 'Cartoon-cowboy-8.gif ',
- '1313955-witch-hat-002_92007.gif ',
- 'Hat_mario_101401.jpg ',
- 'Vector-hat-design1.jpg'
- );
- $ ('# Hat-switch'). on ('click', function (e ){
- E. preventDefault ();
- Var hat = hats [Math. floor (Math. random () * hats. length)];
- Certificate ('.hat').css ('background-image', 'url ('+ hat + ')');
- });
- // @ SourceURL = pen. js
- </Script>
Css3 code:
Html code
- . Wwiaftm-container {
- Position: relative;
- Width: 200px;
- Height: 275px;
- Margin: auto;
- Padding-top: 100px;
- }
- . Profile {
- Border-radius: 100px;
- Overflow: hidden;
- }
- . Wwiaftm {
- Background: #48e0a4;
- Position: absolute;
- Margin: auto;
- Border-radius: 25%;
- }
- . Body-1 {
- Background-repeat: no-repeat;
- Background-position: center;
- Background-size: 70%;
- }
- . Base {
- Width: 60px;
- Height: 80px;
- Bottom: 0;
- Left: 0;
- Right: 0;
- }
- . Hat {
- Top:-120px;
- Height: 80px;
- Width: 100px;
- -Webkit-transform-origin: 50% 100%;
- Transform-origin: 50% 100%;
- -Webkit-transform: rotate3d (0, 0, 1, 0deg );
- Transform: rotate3d (0, 0, 1, 0deg );
- Background-repeat: no-repeat;
- Background-position: center;
- Transparent;
- Background-size: 100%;
- Z-index: 10! Important;
- }
- . Body-1,. body-2,. head {
- Top:-60px;
- Height: 80px;
- Width: 60px;
- -Webkit-transform-origin: 50% 100%;
- Transform-origin: 50% 100%;
- -Webkit-transform: rotate3d (0, 0, 1, 0deg );
- Transform: rotate3d (0, 0, 1, 0deg );
- }
- . Body-1 {
- -Webkit-animation: flail 4S linear infinite;
- Animation: flail 4S linear infinite;
- }
- . Body-2 {
- -Webkit-animation: flail 3 s linear infinite;
- Animation: flail 3 s linear infinite;
- }
- . Head,. hat {
- -Webkit-animation: flail 2 s linear infinite;
- Animation: flail 2 s linear infinite;
- Z-index: 1;
- }
- . Head. eye,. head. mouth {
- Height: 20%;
- Width: 15%;
- Background: black;
- Position: absolute;
- Top: 25%;
- }
- . Head. eye. right {
- Right: 20%;
- }
- . Head. eye. left {
- Left: 20%;
- }
- . Head. mouth {
- Width: 70%;
- Top: 60%;
- Height: 5%;
- Left: 0;
- Right: 0;
- Margin: auto;
- }
- . Arm-1,. arm-2 {
- Position: absolute;
- Width: 50px;
- Height: 20px;
- Right: 90%;
- Top: 25%;
- -Webkit-animation: flail 1 s linear infinite;
- Animation: flail 1 s linear infinite;
- -Webkit-transform-origin: 100% 50%;
- Transform-origin: 100% 50%;
- }
- Arm-1.right,. arm-2.right {
- Left: 90%;
- -Webkit-transform-origin: 0% 50%;
- Transform-origin: 0% 50%;
- }
- . Arm-1. arm-2 {
- -Webkit-animation: flail. 5 s linear infinite;
- Animation: flail. 5 s linear infinite;
- Right: 80%;
- Top: auto;
- }
- . Arm-1. arm-2.right {
- Left: 80%;
- Right: auto;
- }
- @-Webkit-keyframes flail {
- 0% {
- -Webkit-transform: rotate3d (0, 0, 1, 0deg );
- }
- 25% {
- -Webkit-transform: rotate3d (0, 0, 1, 50deg );
- }
- 50% {
- -Webkit-transform: rotate3d (0, 0, 1, 0deg );
- }
- 75% {
- -Webkit-transform: rotate3d (0, 0, 1,-50deg );
- }
- 100% {
- -Webkit-transform: rotate3d (0, 0, 1, 0deg );
- }
- }
- @ Keyframes flail {
- 0% {
- Transform: rotate3d (0, 0, 1, 0deg );
- }
- 25% {
- Transform: rotate3d (0, 0, 1, 50deg );
- }
- 50% {
- Transform: rotate3d (0, 0, 1, 0deg );
- }
- 75% {
- Transform: rotate3d (0, 0, 1,-50deg );
- }
- 100% {
- Transform: rotate3d (0, 0, 1, 0deg );
- }
- }
- . Switch-container {
- Text-align: center;
- Margin-top: 25px;
- }
- # Hat-switch {
- Text-align: center;
- Font-size: 24px;
- Cursor: pointer;
- }