1款恶搞头像殊效的制做全过程 运用css3和jquery
日期:2021-01-20 类型:科技新闻 我要分享
关键词:微信公众号平台小程序,微信打分小程序,小程序发布,小程序大全,微信小程序编程
今日给大伙儿共享1款根据jquery和css3的头像恶搞殊效。这款案例中,1个头像在画面中舞蹈,头像也有讨人喜欢的帽子,点击下面的按钮能够为头像切换不一样的帽子。以下图相片中头像上下晃动,很搞笑幽默,大伙儿还可以自身尝试制做哦。
完成的编码。
html编码:
XML/HTML Code拷贝內容到剪贴板
- <div class="wwiaftm-container">
- <div class="base wwiaftm">
- <div class="body⑴ wwiaftm">
- <div class="body⑵ wwiaftm">
- <div class="hat wwiaftm" style="background-image: url(Mini_Sombrero.png)">
- </div>
- <div class="head wwiaftm">
- <div class="profile">
- <img src="head.png">
- </div>
- </div>
- <div class="wwiaftm arm⑴ left">
- <div class="wwiaftm arm⑵ left">
- <div class="wwiaftm fingers">
- </div>
- </div>
- </div>
- <div class="wwiaftm arm⑴ right">
- <div class="wwiaftm arm⑵ 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⑻.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)];
- $('.hat').css('background-image', 'url(' + hat + ')');
- });
- //@ sourceURL=pen.js
- </script>
css3编码:
CSS 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⑴ {
- background-repeat: no-repeat;
- background-position: center;
- background-size: 70%;
- }
-
- .base {
- width: 60px;
- height: 80px;
- bottombottom: 0;
- left: 0;
- rightright: 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;
- background-color: transparent;
- background-size: 100%;
- z-index: 10 !important;
- }
-
- .body⑴, .body⑵, .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⑴ {
- -webkit-animation: flail 4s linear infinite;
- animation: flail 4s linear infinite;
- }
-
- .body⑵ {
- -webkit-animation: flail 3s linear infinite;
- animation: flail 3s linear infinite;
- }
-
- .head, .hat {
- -webkit-animation: flail 2s linear infinite;
- animation: flail 2s linear infinite;
- z-index: 1;
- }
-
- .head .eye, .head .mouth {
- height: 20%;
- width: 15%;
- background: black;
- position: absolute;
- top: 25%;
- }
-
- .head .eye.rightright {
- rightright: 20%;
- }
-
- .head .eye.left {
- left: 20%;
- }
-
- .head .mouth {
- width: 70%;
- top: 60%;
- height: 5%;
- left: 0;
- rightright: 0;
- margin: auto;
- }
-
- .arm⑴, .arm⑵ {
- position: absolute;
- width: 50px;
- height: 20px;
- rightright: 90%;
- top: 25%;
- -webkit-animation: flail 1s linear infinite;
- animation: flail 1s linear infinite;
- -webkit-transform-origin: 100% 50%;
- transform-origin: 100% 50%;
- }
-
- .arm⑴.rightright, .arm⑵.rightright {
- left: 90%;
- -webkit-transform-origin: 0% 50%;
- transform-origin: 0% 50%;
- }
-
- .arm⑴ .arm⑵ {
- -webkit-animation: flail .5s linear infinite;
- animation: flail .5s linear infinite;
- rightright: 80%;
- top: auto;
- }
-
- .arm⑴ .arm⑵.rightright {
- left: 80%;
- rightright: 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,⑸0deg);
- }
- 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,⑸0deg);
- }
- 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;
- }