一款恶搞头像特效的制作过程 利用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实现的闪烁跳跃进度条示例(附源码)
Aug 19 HTML / CSS
关于css兼容性问题及一些常见问题汇总
May 03 HTML / CSS
CSS3 二级导航菜单的制作的示例
Apr 02 HTML / CSS
详解如何在css3打包后自动追加前缀插件:autoprefixer
Dec 18 HTML / CSS
基于第一个PhoneGap(cordova)的应用详解
May 03 HTML / CSS
HTML5 Canvas——用路径描画线条实例介绍
Jun 09 HTML / CSS
html5小技巧之通过document.head获取head元素
Jun 04 HTML / CSS
HTML5 Canvas的常用线条属性值总结
Mar 17 HTML / CSS
H5 meta小结(前端必看篇)
Aug 24 HTML / CSS
HTML5中的网络存储实现方式
Apr 28 HTML / CSS
CSS巧用渐变实现高级感背景光动画
Dec 06 HTML / CSS
CSS中理解层叠性及权重如何分配
Dec 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源代码
2006/10/09 PHP
php将图片保存为不同尺寸图片的图片类实例
2015/03/30 PHP
ExtJS下grid的一些属性说明
2009/12/13 Javascript
extjs ColumnChart设置不同的颜色实现代码
2013/05/17 Javascript
JS判断字符串长度的5个方法(区分中文和英文)
2014/03/18 Javascript
JS来动态的修改url实现对url的增删查改
2014/09/05 Javascript
简介AngularJS中使用factory和service的方法
2015/06/17 Javascript
jQuery替换节点用法示例(使用replaceWith方法)
2016/09/08 Javascript
JS实现重新加载当前页面或者父页面的几种方法
2016/11/30 Javascript
JavaScript中创建对象的7种模式详解
2017/02/21 Javascript
JavaScript运动框架 多物体任意值运动(三)
2017/05/17 Javascript
使用JavaScript实现在页面中显示距离2017年中秋节的天数
2017/09/26 Javascript
Validform验证时可以为空否则按照指定格式验证
2017/10/20 Javascript
JS实现扫码枪扫描二维码功能
2020/01/03 Javascript
JS如何实现在弹出窗口中加载页面
2020/12/03 Javascript
[57:16]2014 DOTA2华西杯精英邀请赛 5 25 LGD VS VG第二场
2014/05/26 DOTA
如何运行Python程序的方法
2013/04/21 Python
python验证码识别的实例详解
2016/09/09 Python
TensorFlow实现Softmax回归模型
2018/03/09 Python
使用python的pexpect模块,实现远程免密登录的示例
2019/02/14 Python
Python warning警告出现的原因及忽略方法
2020/01/31 Python
PyCharm2020.1.1与Python3.7.7的安装教程图文详解
2020/08/07 Python
详解Django中views数据查询使用locals()函数进行优化
2020/08/24 Python
Python 解析xml文件的示例
2020/09/29 Python
澳大利亚家具和家居用品在线商店:Interiors Online
2018/03/05 全球购物
编程实现当输入某产品代码则打印出该产品记录的功能
2014/05/03 面试题
外贸业务员求职信范文
2013/12/12 职场文书
房屋出售协议书
2014/04/10 职场文书
大学毕业寄语大全
2014/04/10 职场文书
欢度春节标语
2014/07/01 职场文书
商铺消防安全责任书
2014/07/29 职场文书
护士自荐信范文
2015/03/25 职场文书
优质服务标语口号
2015/12/26 职场文书
小学2016年第十八届推普周活动总结
2016/04/05 职场文书
CSS中妙用 drop-shadow 实现线条光影效果
2021/11/11 HTML / CSS
Java 使用类型为Object的变量指向任意类型的对象
2022/04/13 Java/Android