JS的作用:

  1. 操作DOM
  2. 操作AJAX
  3. 其他

一个项目60%的时间在写CSS,20%的时间在写JS, 20%的时间在想自己错在哪儿

材料来源:
codepen:https://codepen.io/

将body的font-size设为100px, 则其他的地方的单位用em就很好换算了

鼻子

做一个钝角三角形

要点:让border-width不同

  1. .nose {
  2. width:0;
  3. height:0;
  4. border-top: 9px solid red;
  5. border-left: 11px solid transparent;
  6. border-right: 11px solid transparent;
  7. }

在三角形上加半个椭圆

要点:用x,y轴半径构成椭圆

  1. .nose::before {
  2. content: '';
  3. display: block;
  4. width: 22px;
  5. height: 5px;
  6. background: black;
  7. position: absolute;
  8. top: -14px;
  9. left:-11px;
  10. border-top-right-radius: 11px 5px; /* 椭圆 x y 轴半径: x=width/2 y=height */
  11. border-top-left-radius: 11px 5px;
  12. box-shadow: 0 -.5px 1px black;
  13. }

眼睛

要点:先居中,然后用transform移到两边

  1. .eye {
  2. border: 3px solid black;
  3. width: 64px;
  4. height: 64px;
  5. position: absolute;
  6. left: 50%;
  7. top: 165px;
  8. margin-left: -32px;
  9. border-radius: 50%;
  10. background:#2e2e2e;
  11. }
  12. .eye.left {
  13. transform: translateX(-110px); /* 让眼睛在鼻子两边 */
  14. }
  15. .eye.right {
  16. transform: translateX(110px);
  17. }
  18. .eye::before{
  19. content: '';
  20. display: block;
  21. width: 32px;
  22. height: 32px;
  23. border: 3px solid black;
  24. background: white;
  25. border-radius: 50%;
  26. position: relative;
  27. left: 6px;
  28. top: -2px;
  29. }

上嘴唇

要点:用translateZ(0)去除rotate产生的边框

  1. .up {
  2. width: 160px;
  3. height: 100px;
  4. position: absolute;
  5. left: 50%;
  6. top: 220px;
  7. margin-left: -80px;
  8. }
  9. .up .lip {
  10. background: #ffe600;
  11. width: 80px;
  12. height: 30px;
  13. position: absolute;
  14. }
  15. .up .lip.left{
  16. border-left: 3px solid black;
  17. border-bottom: 3px solid black;
  18. border-bottom-left-radius: 55px 30px;
  19. transform: rotate(-25deg) translateZ(0); /* 用GPU渲染,去除锯齿边框 */
  20. left: -1.5px;
  21. }
  22. .up .lip.right{
  23. border-right: 3px solid black;
  24. border-bottom: 3px solid black;
  25. border-bottom-right-radius: 55px 30px;
  26. transform: rotate(25deg) translateZ(0);
  27. right: -1.5px;
  28. }

下嘴唇

要点: 用 overflow:hidden 隐藏超出盒子的内容

  1. .down {
  2. width: 140px;
  3. height: 170px;
  4. position: absolute;
  5. left: 50%;
  6. margin-left: -70px;
  7. top: 232px;
  8. overflow: hidden;
  9. z-index: -1;
  10. }
  11. .down .inner {
  12. width: 180px;
  13. height: 900px;
  14. border: 4px solid black;
  15. background: #9b000a;
  16. position: absolute;
  17. bottom: 0;
  18. left: 50%;
  19. margin-left: -90px;
  20. border-bottom-left-radius: 100%;
  21. border-bottom-right-radius: 100%;
  22. overflow: hidden;
  23. }
  24. .down .inner .outer {
  25. width: 200px;
  26. height: 500px;
  27. background: #ff485f;
  28. position: absolute;
  29. bottom: -360px;
  30. left: 50%;
  31. margin-left: -100px;
  32. border-top-left-radius: 95px 150px;
  33. border-top-right-radius: 95px 150px;
  34. }

鼻子动画

要点:transform-origin设置变形的原点

  1. @keyframes move {
  2. 0% {transform: rotate(0)}
  3. 33% {transform: rotate(4deg)}
  4. 66% {transform: rotate(-4deg)}
  5. 100% {transform: rotate(0)}
  6. }
  7. .nose:hover {
  8. transform-origin: center bottom;
  9. animation: move 100ms infinite;
  10. }

眼球转动效果

  1. @keyframes eyes-move {
  2. 0%,20% {top: -1px; left: 7px;}
  3. 5% {top: 5px; left: 25px;}
  4. 10% {top: 20px; left: 29px;}
  5. 15% {top: 25px; left: 5px;}
  6. }
  7. .eye::before {
  8. animation: eyes-move 4s infinite linear;
  9. }

眨眼效果

通过移动位于眼睛上方与背景同色的div来实现
也可以用opacity调整透明度来实现,1表示不透明,0表示透明

  1. @keyframes eye-close {
  2. 0%, 23%, 33%, 100% {top: -100px;}
  3. 28% {top: -55px;}
  4. }
  5. .eye::after {
  6. content: '';
  7. display: block;
  8. width: 66px;
  9. height: 66px;
  10. position: relative;
  11. top: -100px;
  12. left: -4px;
  13. background: #ffe600;
  14. animation: eye-close 4s infinite linear;
  15. }

颜色渐变淡出效果

要点:ease-out

  1. .cheek {
  2. animation: light 4s ease-out infinite;
  3. }
  4. @keyframes light {
  5. 55% {background: #ff0000;}
  6. 60% {background: #FFFA3F;}
  7. }