一款恶搞头像特效的制作过程 利用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条纹背景制作的实战攻略
May 31 HTML / CSS
html5 localStorage本地存储_动力节点Java学院整理
Jul 06 HTML / CSS
值得收藏的HTML5资源(学习html5的朋友可以收藏下)
Jul 20 HTML / CSS
HTML5 中新的全局属性(整理)
Jul 31 HTML / CSS
通过HTML5规范搞定i、em、b、strong元素的区别
Mar 04 HTML / CSS
详解HTML5 data-* 自定义属性
Jan 24 HTML / CSS
HTML5中form如何关闭自动完成功能的方法
Jul 02 HTML / CSS
完美实现CSS垂直居中的11种方法
Mar 27 HTML / CSS
奇妙的 CSS shapes(CSS图形)
Apr 05 HTML / CSS
分享几个实用的CSS代码块
Jun 10 HTML / CSS
前端使用svg图片改色实现示例
Jul 23 HTML / CSS
什么是clearfix (一文搞清楚css清除浮动clearfix)
May 21 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
新的一年,新的期待:DC在2020年的四部动画电影
2020/01/01 欧美动漫
动易数据转成dedecms的php程序
2007/04/07 PHP
PHP判断变量是否为0的方法
2014/02/08 PHP
php检测useragent版本示例
2014/03/24 PHP
php判断两个日期之间相差多少个月份的方法
2015/06/18 PHP
php 截取utf-8格式的字符串实例代码
2016/10/30 PHP
JavaScript网页制作特殊效果用随机数
2007/05/22 Javascript
javascript 二维数组的实现与应用
2010/03/16 Javascript
Jquery 滑入滑出效果实现代码
2010/03/27 Javascript
jQuery dialog 异步调用ashx,webservice数据的代码
2010/08/03 Javascript
Jquery 数据选择插件Pickerbox使用介绍
2012/08/24 Javascript
js 验证密码强弱的小例子
2013/03/21 Javascript
JQuery解析HTML、JSON和XML实例详解
2014/03/29 Javascript
Javascript Memoizer浅析
2014/10/16 Javascript
node.js中的console.time方法使用说明
2014/12/09 Javascript
bootstrap制作jsp页面(根据值让table显示选中)
2017/01/05 Javascript
Vue编写多地区选择组件
2017/08/21 Javascript
微信小程序实现点击卡片 翻转效果
2019/09/04 Javascript
Python实现配置文件备份的方法
2015/07/30 Python
Python简单连接MongoDB数据库的方法
2016/03/15 Python
Python编程二分法实现冒泡算法+快速排序代码示例
2018/01/15 Python
浅谈Python中重载isinstance继承关系的问题
2018/05/04 Python
pyqt5 comboBox获得下标、文本和事件选中函数的方法
2019/06/14 Python
django 基于中间件实现限制ip频繁访问过程详解
2019/07/30 Python
Python Django 命名空间模式的实现
2019/08/09 Python
CSS3实现王者荣耀匹配人员加载页面的方法
2019/04/16 HTML / CSS
HTML5-WebSocket实现聊天室示例
2016/12/15 HTML / CSS
解决HTML5手机端页面缩放的问题
2017/10/27 HTML / CSS
新西兰第一的行李箱网站:luggage.co.nz
2019/07/22 全球购物
美国乒乓球设备、配件和服装品牌:Killerspin
2020/06/07 全球购物
个人简历自我鉴定
2013/10/11 职场文书
安全教育演讲稿
2014/05/09 职场文书
机修车间主任岗位职责
2015/04/08 职场文书
Python爬取英雄联盟MSI直播间弹幕并生成词云图
2021/06/01 Python
JavaWeb 入门篇(3)ServletContext 详解 具体应用
2021/07/16 Java/Android
浅谈MySQL中的六种日志
2022/03/23 MySQL