一款恶搞头像特效的制作过程 利用css3和jquery


Posted in HTML / CSS onNovember 21, 2014

今天给大家分享一款基于jquery和css3的头像恶搞特效。这款实例中,一个头像在画面中跳舞,头像还有可爱的帽子,单击下面的按钮可以为头像切换不同的帽子。如下图照片中头像左右摇晃,很搞笑,大家也可以自己尝试制作哦。

一款恶搞头像特效的制作过程 利用css3和jquery

一款恶搞头像特效的制作过程 利用css3和jquery一款恶搞头像特效的制作过程 利用css3和jquery

实现的代码。

html代码:

XML/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.                             <img src="head.png">  
  10.                         </div>  
  11.                     </div>  
  12.                     <div class="wwiaftm arm-1 left">  
  13.                         <div class="wwiaftm arm-2 left">  
  14.                             <div class="wwiaftm fingers">  
  15.                             </div>  
  16.                         </div>  
  17.                     </div>  
  18.                     <div class="wwiaftm arm-1 right">  
  19.                         <div class="wwiaftm arm-2 right">  
  20.                             <div class="wwiaftm fingers">  
  21.                             </div>  
  22.                         </div>  
  23.                     </div>  
  24.                 </div>  
  25.             </div>  
  26.         </div>  
  27.     </div>  
  28.     <div class="switch-container">  
  29.         <button id="hat-switch">  
  30.             Hat Me!</button>  
  31.     </div>  
  32.     <script src='jquery.min.js'></script>  
  33.     <script>        var hats = Array(   
  34.   'Mini_Sombrero.png', 'med.png',   
  35.   'svg.med.png',   
  36.   'cartoon-cowboy-8.gif',   
  37.   '1313955-witch-hat-002_92007.gif',   
  38.   'hat_mario_101401.jpg',   
  39.   'vector-hat-design1.jpg'   
  40. );   
  41.   
  42.         $('#hat-switch').on('click', function (e) {   
  43.             e.preventDefault();   
  44.             var hat = hats[Math.floor(Math.random() * hats.length)];   
  45.             $('.hat').css('background-image', 'url(' + hat + ')');   
  46.         });   
  47.         //@ sourceURL=pen.js   
  48.     </script>  

css3代码:

CSS Code复制内容到剪贴板
  1. .wwiaftm-container {   
  2.   positionrelative;   
  3.   width200px;   
  4.   height275px;   
  5.   marginauto;   
  6.   padding-top100px;   
  7. }   
  8.   
  9. .profile {   
  10.   border-radius: 100px;   
  11.   overflowhidden;   
  12. }   
  13.   
  14. .wwiaftm {   
  15.   background#48e0a4;   
  16.   positionabsolute;   
  17.   marginauto;   
  18.   border-radius: 25%;   
  19. }   
  20.   
  21. .body-1 {   
  22.   background-repeatno-repeat;   
  23.   background-positioncenter;   
  24.   background-size: 70%;   
  25. }   
  26.   
  27. .base {   
  28.   width60px;   
  29.   height80px;   
  30.   bottombottom: 0;   
  31.   left: 0;   
  32.   rightright: 0;   
  33. }   
  34.   
  35. .hat {   
  36.   top: -120px;   
  37.   height80px;   
  38.   width100px;   
  39.   -webkit-transform-origin: 50% 100%;   
  40.   transform-origin: 50% 100%;   
  41.   -webkit-transform: rotate3d(0,0,1,0deg);   
  42.   transform: rotate3d(0,0,1,0deg);   
  43.   background-repeatno-repeat;   
  44.   background-positioncenter;   
  45.   background-colortransparent;   
  46.   background-size: 100%;   
  47.   z-index: 10 !important;   
  48. }   
  49.   
  50. .body-1, .body-2, .head {   
  51.   top: -60px;   
  52.   height80px;   
  53.   width60px;   
  54.   -webkit-transform-origin: 50% 100%;   
  55.   transform-origin: 50% 100%;   
  56.   -webkit-transform: rotate3d(0,0,1,0deg);   
  57.   transform: rotate3d(0,0,1,0deg);   
  58. }   
  59.   
  60. .body-1 {   
  61.   -webkit-animation: flail 4s linear infinite;   
  62.   animation: flail 4s linear infinite;   
  63. }   
  64.   
  65. .body-2 {   
  66.   -webkit-animation: flail 3s linear infinite;   
  67.   animation: flail 3s linear infinite;   
  68. }   
  69.   
  70. .head, .hat {   
  71.   -webkit-animation: flail 2s linear infinite;   
  72.   animation: flail 2s linear infinite;   
  73.   z-index: 1;   
  74. }   
  75.   
  76. .head .eye, .head .mouth {   
  77.   height: 20%;   
  78.   width: 15%;   
  79.   backgroundblack;   
  80.   positionabsolute;   
  81.   top: 25%;   
  82. }   
  83.   
  84. .head .eye.rightright {   
  85.   rightright: 20%;   
  86. }   
  87.   
  88. .head .eye.left {   
  89.   left: 20%;   
  90. }   
  91.   
  92. .head .mouth {   
  93.   width: 70%;   
  94.   top: 60%;   
  95.   height: 5%;   
  96.   left: 0;   
  97.   rightright: 0;   
  98.   marginauto;   
  99. }   
  100.   
  101. .arm-1, .arm-2 {   
  102.   positionabsolute;   
  103.   width50px;   
  104.   height20px;   
  105.   rightright: 90%;   
  106.   top: 25%;   
  107.   -webkit-animation: flail 1s linear infinite;   
  108.   animation: flail 1s linear infinite;   
  109.   -webkit-transform-origin: 100% 50%;   
  110.   transform-origin: 100% 50%;   
  111. }   
  112.   
  113. .arm-1.rightright, .arm-2.rightright {   
  114.   left: 90%;   
  115.   -webkit-transform-origin: 0% 50%;   
  116.   transform-origin: 0% 50%;   
  117. }   
  118.   
  119. .arm-1 .arm-2 {   
  120.   -webkit-animation: flail .5s linear infinite;   
  121.   animation: flail .5s linear infinite;   
  122.   rightright: 80%;   
  123.   topauto;   
  124. }   
  125.   
  126. .arm-1 .arm-2.rightright {   
  127.   left: 80%;   
  128.   rightrightauto;   
  129. }   
  130.   
  131. @-webkit-keyframes flail {   
  132.   0% {   
  133.     -webkit-transform: rotate3d(0,0,1,0deg);   
  134.   }   
  135.   25% {   
  136.     -webkit-transform: rotate3d(0,0,1,50deg);   
  137.   }   
  138.   50% {   
  139.     -webkit-transform: rotate3d(0,0,1,0deg);   
  140.   }   
  141.   75% {   
  142.     -webkit-transform: rotate3d(0,0,1,-50deg);   
  143.   }   
  144.   100% {   
  145.     -webkit-transform: rotate3d(0,0,1,0deg);   
  146.   }   
  147. }   
  148.   
  149. @keyframes flail {   
  150.   0% {   
  151.     transform: rotate3d(0,0,1,0deg);   
  152.   }   
  153.   25% {   
  154.     transform: rotate3d(0,0,1,50deg);   
  155.   }   
  156.   50% {   
  157.     transform: rotate3d(0,0,1,0deg);   
  158.   }   
  159.   75% {   
  160.     transform: rotate3d(0,0,1,-50deg);   
  161.   }   
  162.   100% {   
  163.     transform: rotate3d(0,0,1,0deg);   
  164.   }   
  165. }   
  166.   
  167. .switch-container {   
  168.   text-aligncenter;   
  169.   margin-top25px;   
  170. }   
  171.   
  172. #hat-switch {   
  173.   text-aligncenter;   
  174.   font-size24px;   
  175.   cursorpointer;   
  176. }  
HTML / CSS 相关文章推荐
CSS3教程(8):CSS3透明度指南
Apr 02 HTML / CSS
带有css3动画效果的兼容多浏览器简单导航条示例
Jan 26 HTML / CSS
一款利用纯css3实现的超炫3D表单的实例教程
Dec 01 HTML / CSS
CSS3中currentColor关键字的妙用
Feb 27 HTML / CSS
使用CSS3美化HTML表单的技巧演示
May 17 HTML / CSS
浅谈CSS3特性查询(Feature Query: @supports)功能简介
Jul 31 HTML / CSS
网页中的电话号码如何实现一键直呼效果_附示例
Mar 15 HTML / CSS
HTML5 Canvas的事件处理介绍
Apr 24 HTML / CSS
利用HTML5 Canvas制作键盘及鼠标动画的实例分享
Mar 15 HTML / CSS
HTML5去掉输入框type为number时的上下箭头的实现方法
Jan 03 HTML / CSS
详解HTML5布局和HTML5标签
Oct 26 HTML / CSS
通过feDisplacementMap和feImage实现水波特效
Apr 24 HTML / CSS
html5+css3之CSS中的布局与Header的实现
Nov 21 #HTML / CSS
html5+css3气泡组件的实现
Nov 21 #HTML / CSS
纯css3实现的动画按钮的实例教程
Nov 17 #HTML / CSS
实列教程 一款基于jquery和css3的响应式二级导航菜单
Nov 13 #HTML / CSS
一款纯css3实现的颜色渐变按钮的代码教程
Nov 12 #HTML / CSS
css3实现超炫风车特效
Nov 12 #HTML / CSS
用CSS3来实现社交分享按钮
Nov 11 #HTML / CSS
You might like
php数组中删除元素的实现代码
2012/06/22 PHP
用PHP编写和读取XML的几种方式
2013/01/12 PHP
在win7中搭建Linux+PHP 开发环境
2014/10/08 PHP
php+curl 发送图片处理代码分享
2015/07/09 PHP
实例讲解通过​PHP创建数据库
2019/01/20 PHP
PHP的cookie与session原理及用法详解
2019/09/27 PHP
gearman中任务的优先级和返回状态实例分析
2020/02/27 PHP
Javascript 验证上传图片大小[客户端]
2009/08/01 Javascript
Jquery css函数用法(判断标签是否拥有某属性)
2011/05/28 Javascript
javascript 保存文件到本地实现方法
2012/11/29 Javascript
深入理解javascript变量声明
2014/11/20 Javascript
Javascript OOP之面向对象
2016/07/31 Javascript
微信小程序 实现点击添加移除class
2017/06/12 Javascript
angular中的cookie读写方法
2017/08/02 Javascript
ionic2屏幕适配实现适配手机、平板等设备的示例代码
2017/08/11 Javascript
JavaScript html5 canvas实现图片上画超链接
2017/10/20 Javascript
vue-cli项目修改文件热重载失效的解决方法
2018/09/19 Javascript
ElementUI Tag组件实现多标签生成的方法示例
2019/07/08 Javascript
详解vuex的简单todolist例子
2019/07/14 Javascript
从0到1学习JavaScript编写贪吃蛇游戏
2020/07/28 Javascript
Python如何为图片添加水印
2016/11/25 Python
用Python一键搭建Http服务器的方法
2018/06/01 Python
python 按钮点击关闭窗口的实现
2020/03/04 Python
如何打包Python Web项目实现免安装一键启动的方法
2020/05/21 Python
Keras SGD 随机梯度下降优化器参数设置方式
2020/06/19 Python
python空元组在all中返回结果详解
2020/12/15 Python
关于多种方式完美解决Python pip命令下载第三方库的问题
2020/12/21 Python
Python 可视化神器Plotly详解
2020/12/26 Python
.NET里面如何取得当前的屏幕分辨率
2012/12/06 面试题
后勤人员自我鉴定
2013/10/20 职场文书
医学毕业生自我鉴定
2013/10/30 职场文书
党员演讲稿
2014/09/04 职场文书
学习党的群众路线实践活动思想汇报
2014/09/12 职场文书
2014年图书馆工作总结
2014/11/25 职场文书
2015年学校教科室工作总结
2015/07/20 职场文书
成本低的5个创业项目:投资小、赚钱快
2019/08/20 职场文书