时间:14-03-28 栏目:html5/css3, JQUERY 作者:zongyan86 评论:1 点击: 4,834 次
每天都是新的一天,每天都是快乐的一天,每天都应当给自己一个笑脸 。当你手上没有镜子,自拍神器又刚好没电,那就用你的web开发技术给自己码一个出来吧!主要的还是css3的应用,记得用好点的浏览器哦 。
html:
<div class="eyes"> <div class="eye EL"><div class="pupil"></div></div> <div class="eye ER"><div class="pupil"></div></div> /div> <div class="smile"> <div class="teeth"></div> <div class="tongue"></div> </div>
css:
* { box-sizing: border-box; } .container { width: 80%; min-height: 400px; background-color: #ee3a4c; overflow: auto; display: block; margin: 0 auto; } .eyes { width: 400px; display: block; margin: 0 auto; text-align: center; margin-top: 66.66667px; margin-bottom: 25px; } .eye { height: 100px; width: 100px; background-color: #ee3a4c; border: 4px solid white; border-radius: 100%;//变圆形 display: inline-block; margin: 0 20px; position: relative; //相对定位 padding: 20px; overflow: hidden; } .eye .pupil { height: 25px; width: 25px; border-radius: 100%; //变圆 display: inline-block; background-color: white; position: absolute; margin-left: -10px; left: 50px; margin: 10px; } .smile { height: 100px; width: 200px; border-radius: 0 0 200px 200px; //半圆 background: #770f1a; margin: 0 auto; overflow: hidden; transition: all .4s; //动画效果 transform-origin: center; } .smile:hover { transition: all .4s; height: 33.33333px; width: 33.33333px; border-radius: 100%; margin-top: 50px; } .smile:hover .teeth { margin-left: -25px; margin-top: -40px; transition: all .4s; } .smile:hover .tongue { transition: all .4s; margin-left: -50px; /*margin-top: $tongueDimensions*2;*/ } .smile .teeth { background-color: #fff; transition: all .4s; height: 33.33333px; width: 33.33333px; margin-left: 56.66667px; position: relative; } .smile .teeth:after { content: ""; //一个变成两 :after background-color: #fff; height: 33.33333px; width: 33.33333px; position: absolute; left: 50px; top: 0; z-index: 10000; } .smile .tongue { transition: all .4s; height: 100px; width: 100px; background-color: pink; border-radius: 100%; margin-top: 40px; margin-left: 15px; display: inline-block; position: relative; } .smile .tongue:after { content: ''; height: 100px; width: 100px; background-color: pink; border-radius: 100%; display: inline-block; position: absolute; left: 50px; /*margin-top: 0; margin-left: -($tongueDimensions/3);*/ }
js:
var limitX = 50, limitY = 50; var containerW = $('.container').width(); var containerH = $('.container').height(); $( ".container" ).mousemove(function( e ) { var mouseY = Math.min(e.clientY/(containerH*.01), limitY); var mouseX = Math.min(e.clientX/(containerW*.01), limitX); $('.pupil').css('top', mouseY); $('.pupil').css('left', mouseX); console.log(e.clientY+' '+e.clientX);//眼球跟随鼠标的效果,是不是也很简单 });
web开发分享自 http://www.html5tricks.com/demo/html5-css3-smile-face/index.html 点击查看效果哦
声明: 本文由( zongyan86 )原创编译,转载请保留链接: 用css3给自己一个笑脸