[关闭]
@fantaghiro 2014-12-01T09:33:56.000000Z 字数 60651 阅读 1891

妙味课堂-CSS3

学习笔记 js 前端 妙味课堂 CSS3


学习CSS3之前先讲几个问题:

CSS3选择器 - 属性选择器

属性选择器

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>CSS3选择器</title>
  6. <style>
  7. p {height: 30px; border: 1px solid #000;}
  8. /*p[miaov] {background: red;} */ /*所有四个*/
  9. /*p[miaov=g-xM] {background: red;}*/ /*第四个小美*/
  10. /*p[miaov~=old] {background: red;}*/ /*第一个leo*/
  11. /*p[miaov^=g] {background: pink;}*/ /*第四个小美*/
  12. /*p[miaov$=M] {background: #cc0;}*/ /*第三、四个:子鼠和小美*/
  13. /*p[miaov*=d] {background: purple;}*/ /*第一、二个:leo和杜鹏*/
  14. /*p[miaov|=b] {background: purple;}*/ /*第一、二、三和最后一个:leo、杜鹏和子鼠、无名氏*/
  15. </style>
  16. </head>
  17. <body>
  18. <p miaov="b-leo old">leo</p>
  19. <p miaov="b-dp">杜鹏</p>
  20. <p miaov="b-zM">子鼠</p>
  21. <p miaov="g-xM">小美</p>
  22. <p miaov="b">无名氏</p>
  23. </body>
  24. </html>

实例:百度文库

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>百度文库</title>
  6. <style>
  7. p {height: 30px; line-height: 30px; font-size: 12px; border: 1px solid #000;}
  8. p a {background: url(img/w.gif) no-repeat 3px center; padding-left: 20px; display: block;}
  9. p a[href*=text]{background: url(img/text.gif) no-repeat 3px center;}
  10. p a[href*=pdf]{background: url(img/swf.gif) no-repeat 3px center;}
  11. p a[href*=exl]{background: url(img/x.gif) no-repeat 3px center;}
  12. </style>
  13. </head>
  14. <body>
  15. <p><a href="http://www.miaov.com/doc/javascript.html">妙味课堂</a></p>
  16. <p><a href="http://www.miaov.com/text/javascript.html">妙味课堂</a></p>
  17. <p><a href="http://www.miaov.com/pdf/javascript.html">妙味课堂</a></p>
  18. <p><a href="http://www.miaov.com/doc/javascript.html">妙味课堂</a></p>
  19. <p><a href="http://www.miaov.com/exl/javascript.html">妙味课堂</a></p>
  20. </body>
  21. </html>

CSS3选择器 - 结构性伪类

结构性伪类

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>结构性伪类</title>
  6. <style>
  7. p {height: 30px; border: 1px solid #000;}
  8. span {display: block; height: 20px;}
  9. /*p:nth-child(1) {background: red;} *//*注意nth-child是从1开始计数的*/
  10. /*p:nth-child(odd) {background: red;} *//*奇数*/
  11. /*p:nth-child(even) {background: blue;} *//*偶数*/
  12. /*p:nth-child(2n) {background: green;}*/
  13. /*p:nth-child(2n-1) {background: yellow;}*/
  14. /*p:nth-child(3n) {background: purple;}*/
  15. /*p:nth-child(2) : 找到p标签父级下的第二个子元素,并且这个元素还得是p标签*/
  16. /*body *:nth-child(2) {background: red;}*/
  17. /*body *:nth-last-child(2) {background: green;} */ /*:nth-last-child()代表从后往前找。:nth-child()括号中写什么,:nth-last-child()里面也可以写,都支持,只不过查找顺序变成了从后向前*/
  18. /*p:nth-of-type(2) {background: red;}*/ /*找到p标签的父级下的第二个p标签*/
  19. /*body *:nth-of-type(2) {background: brown;}*/ /*body下的第二个p标签和第二个h1标签都会被找到*/
  20. /*p:nth-last-of-type(2) {background: purple;}*/ /*:nth-last-of-type()与:nth-of-type()都一样,只不过顺序反过来而已*/
  21. /*p:first-child {background: green;}*/ /*:first-child == :nth-child(1)*/
  22. /*:last-child == :nth-last-child(1)*/
  23. /*:first-of-type == :nth-of-type(1)*/
  24. /*:last-of-type == :nth-last-of-type(1)*/
  25. /*p:empty {background: black;}*/ /*不包含子元素(子元素包括文本节点)的p标签*/
  26. /*span:only-of-type {background: gray;}*/
  27. /*p *:only-of-type {background: red;}*/
  28. /*p *:only-child {background: blue;}*/
  29. </style>
  30. </head>
  31. <body>
  32. <p>p1</p>
  33. <h1>h1</h1>
  34. <p>p2</p>
  35. <h1>h2</h1>
  36. <p>p3</p>
  37. <h1>h3</h1>
  38. <p></p>
  39. <p>p5<span></span></p>
  40. <p><span></span><a href="#">链接</a></p>
  41. </body>
  42. </html>

新浪头部导航

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>新浪头部导航</title>
  6. <style>
  7. .list {margin: 0; padding: 0; list-style: none;}
  8. .list li {width: 150px; border-right: 1px solid #000; float: left;}
  9. .list li:last-of-type {border: none;}
  10. .list a {float: left; width: 40px; margin: 0 5px; font: 12px/30px "宋体"; text-align: center;}
  11. .list li a:nth-of-type(3n+1) {font-weight: bold;}
  12. .list li:nth-child(3) a:nth-child(2) {color: red;}
  13. </style>
  14. </head>
  15. <body>
  16. <ul class="list">
  17. <li>
  18. <a href="#">妙味</a>
  19. <a href="#">妙味</a>
  20. <a href="#">妙味</a>
  21. <a href="#">妙味</a>
  22. <a href="#">妙味</a>
  23. <a href="#">妙味</a>
  24. <a href="#">妙味</a>
  25. <a href="#">妙味</a>
  26. <a href="#">妙味</a>
  27. </li>
  28. <li>
  29. <a href="#">妙味</a>
  30. <a href="#">妙味</a>
  31. <a href="#">妙味</a>
  32. <a href="#">妙味</a>
  33. <a href="#">妙味</a>
  34. <a href="#">妙味</a>
  35. <a href="#">妙味</a>
  36. <a href="#">妙味</a>
  37. <a href="#">妙味</a>
  38. </li>
  39. <li>
  40. <a href="#">妙味</a>
  41. <a href="#">妙味</a>
  42. <a href="#">妙味</a>
  43. <a href="#">妙味</a>
  44. <a href="#">妙味</a>
  45. <a href="#">妙味</a>
  46. <a href="#">妙味</a>
  47. <a href="#">妙味</a>
  48. <a href="#">妙味</a>
  49. </li>
  50. <li>
  51. <a href="#">妙味</a>
  52. <a href="#">妙味</a>
  53. <a href="#">妙味</a>
  54. <a href="#">妙味</a>
  55. <a href="#">妙味</a>
  56. <a href="#">妙味</a>
  57. <a href="#">妙味</a>
  58. <a href="#">妙味</a>
  59. <a href="#">妙味</a>
  60. </li>
  61. <li>
  62. <a href="#">妙味</a>
  63. <a href="#">妙味</a>
  64. <a href="#">妙味</a>
  65. <a href="#">妙味</a>
  66. <a href="#">妙味</a>
  67. <a href="#">妙味</a>
  68. <a href="#">妙味</a>
  69. <a href="#">妙味</a>
  70. <a href="#">妙味</a>
  71. </li>
  72. <li>
  73. <a href="#">妙味</a>
  74. <a href="#">妙味</a>
  75. <a href="#">妙味</a>
  76. <a href="#">妙味</a>
  77. <a href="#">妙味</a>
  78. <a href="#">妙味</a>
  79. <a href="#">妙味</a>
  80. <a href="#">妙味</a>
  81. <a href="#">妙味</a>
  82. </li>
  83. <li>
  84. <a href="#">妙味</a>
  85. <a href="#">妙味</a>
  86. <a href="#">妙味</a>
  87. <a href="#">妙味</a>
  88. <a href="#">妙味</a>
  89. <a href="#">妙味</a>
  90. <a href="#">妙味</a>
  91. <a href="#">妙味</a>
  92. <a href="#">妙味</a>
  93. </li>
  94. </ul>
  95. </body>
  96. </html>

CSS3选择器 - 伪类和伪元素

:target伪类

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>伪类和伪元素</title>
  6. <style>
  7. div {width: 300px; height: 200px; background: #000; font: 50px/200px "微软雅黑"; color: #fff; text-align: center; display: none;}
  8. div:target {display: block;}
  9. /* :target哈希值对应的东西,点击第一个a标签,第一个div就会显示出来,因为相当于给#div1设置了display: block;的样式,点击后面两个a标签同理 */
  10. </style>
  11. </head>
  12. <body>
  13. <a href="#div1">div1</a>
  14. <a href="#div2">div2</a>
  15. <a href="#div3">div3</a>
  16. <div id="div1">div1</div>
  17. <div id="div2">div2</div>
  18. <div id="div3">div3</div>
  19. </body>
  20. </html>

:disabled与:enabled

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>伪类和伪元素</title>
  6. <style>
  7. input {width: 100px; height: 30px; color: #000;}
  8. input:enabled {color: red;}
  9. input:disabled {background: gray;}
  10. </style>
  11. </head>
  12. <body>
  13. <input type="text" value="请输入" disabled>
  14. </body>
  15. </html>

:checked

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>伪类和伪元素</title>
  6. <style>
  7. input:checked {width: 100px; height: 100px;}
  8. </style>
  9. </head>
  10. <body>
  11. <input type="checkbox" />
  12. </body>
  13. </html>

E~F

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>伪类和伪元素</title>
  6. <style>
  7. p~h1 {background: red;}
  8. </style>
  9. </head>
  10. <body>
  11. <h1>h1</h1>
  12. <p>p</p>
  13. <h1>h1</h1>
  14. <h1>h1</h1>
  15. </body>
  16. </html>

模拟单选框

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>模拟单选框</title>
  6. <style>
  7. label {float: left; margin: 0 5px; overflow: hidden; position: relative;}
  8. label input {position: absolute; left: -50px; top: -50px;}
  9. span {float: left; width: 50px; height: 50px; border: 3px solid #000;}
  10. input:checked~span {background: red;}
  11. </style>
  12. </head>
  13. <body>
  14. <label>
  15. <input type="radio" name="tab">
  16. <span></span>
  17. </label>
  18. <label>
  19. <input type="radio" name="tab">
  20. <span></span>
  21. </label>
  22. <label>
  23. <input type="radio" name="tab">
  24. <span></span>
  25. </label>
  26. </body>
  27. </html>

文本新增伪类

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>文本新增</title>
  6. <style>
  7. p {width: 300px; border: 1px solid #000; font: 12px/30px "宋体"; padding: 10px;}
  8. p:first-line {background: red;}
  9. p:first-letter {font-size: 30px;} /*注意:通过:first-letter设置样式的文本是选不中的*/
  10. p::selection {background: #f60; color: #690;} /*文本被选中的样式 注意使用双冒号*/
  11. p::before {content: "MiaoV"; display: block; border: 1px solid #000;} /*::before和::after 单冒号和双冒号都认*/
  12. p::after {content: "MiaoV"; display: block; border: 1px solid #000;}
  13. </style>
  14. </head>
  15. <body>
  16. <p>前端开发的世界从未有过无声的寂静,精彩纷呈的互联网也不曾出现片刻安宁,在HTML5&CSS3被炒至沸沸扬扬的今天,全面系统地掌握此项技能,是加重技术含金量的重要砝码!妙味课堂现已为你开启一个崭新的职业规划……</p>
  17. </body>
  18. </html>

排除元素

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. h1:not(.h2) {background: red;}
  8. </style>
  9. </head>
  10. <body>
  11. <h1>h1</h1>
  12. <h1 class="h2">h1</h1>
  13. <h1>h1</h1>
  14. </body>
  15. </html>

新增颜色模式

背景透明、文字不透明

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>rgba</title>
  6. <style>
  7. body {background: green;}
  8. .box {width: 200px; height: 200px; background: rgba(0, 0, 0, 0.5); color: #fff; font: 40px/100px "微软雅黑"; text-align: center;} /*背景透明但文字不透明*/
  9. </style>
  10. </head>
  11. <body>
  12. <div class="box">妙味课堂</div>
  13. </body>
  14. </html>

背景不透明、文字透明

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>rgba</title>
  6. <style>
  7. .box {width: 200px; height: 200px; background: green; color: rgba(255, 255, 255, 0.5); font: 80px/100px "微软雅黑"; text-align: center;} /*背景不透明但文字透明*/
  8. </style>
  9. </head>
  10. <body>
  11. <div class="box">妙味课堂</div>
  12. </body>
  13. </html>

背景不透明、边框透明

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>rgba</title>
  6. <style>
  7. .box {width: 200px; height: 190px; background: green; color: rgba(255, 255, 255, 0.5); font: 80px/90px "微软雅黑"; text-align: center; border: 10px solid rgba(0, 0, 0, 0.3);} /*边框颜色透明,会把后面背景露出来*/
  8. </style>
  9. </head>
  10. <body>
  11. <div class="box">妙味课堂</div>
  12. </body>
  13. </html>

文字阴影

text-shadow基本应用

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>文字阴影</title>
  6. <style>
  7. h1 { font: 100px/200px "微软雅黑"; text-align: center; text-shadow: 0 0 10px red; }
  8. </style>
  9. </head>
  10. <body>
  11. <h1>妙味课堂</h1>
  12. </body>
  13. </html>

文字阴影的叠加

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>文字阴影的叠加</title>
  6. <style>
  7. h1 { font: 100px/200px "微软雅黑"; text-align: center; text-shadow: -5px -10px 1px red, 5px 10px 2px green, 1px 1px 5px yellow; }
  8. </style>
  9. </head>
  10. <body>
  11. <h1>妙味课堂</h1>
  12. </body>
  13. </html>

浮雕文字效果

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>文字阴影</title>
  6. <style>
  7. h1 { font: 100px/200px "微软雅黑"; text-align: center; color: #fff; text-shadow: 2px 2px 4px #000; }
  8. </style>
  9. </head>
  10. <body>
  11. <h1>妙味课堂</h1>
  12. </body>
  13. </html>

文字模糊效果

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>文字模糊</title>
  6. <style>
  7. h1 { font: 100px/200px "微软雅黑"; text-align: center; color: #000; text-shadow: 0 0 0 rgba(0, 0, 0, 1); border: 1px solid #000; transition: 1s; }
  8. h1:hover {color: rgba(0, 0, 0, 0); text-shadow: 0 0 20px rgba(0, 0, 0, 0.5);}
  9. </style>
  10. </head>
  11. <body>
  12. <h1>妙味课堂</h1>
  13. </body>
  14. </html>

文字描边

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>文字描边</title>
  6. <style>
  7. h1 { font: 100px/200px "微软雅黑"; text-align: center; color: #000; -webkit-text-stroke: 3px red; }
  8. </style>
  9. </head>
  10. <body>
  11. <h1>妙味课堂</h1>
  12. </body>
  13. </html>

新增文本功能

direction

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>文字排版</title>
  6. <style>
  7. p {width: 300px; border: 1px solid #000; font: 14px/30px "宋体"; direction: rtl; unicode-bidi: bidi-override;}
  8. </style>
  9. </head>
  10. <body>
  11. <p>妙味课堂</p>
  12. </body>
  13. </html>

超出显示省略号

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>文字排版</title>
  6. <style>
  7. p {width: 300px; border: 1px solid #000; font: 14px/30px "宋体"; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
  8. </style>
  9. </head>
  10. <body>
  11. <p>妙味课堂具有人性化的IT培训机构妙味课堂具有人性化的IT培训机构</p>
  12. </body>
  13. </html>

自定义文字

  1. @font-face {
  2. font-family: 'miaov';
  3. src: url('111-webfont.eot');
  4. src: url('111-webfont.eot?#iefix') format('embedded-opentype'),
  5. url('111-webfont.woff') format('woff'),
  6. url('111-webfont.ttf') format('truetype'),
  7. url('111-webfont.svg#untitledregular') format('svg');
  8. font-weight: normal;
  9. font-style: normal;
  10. }

弹性盒模型

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>弹性盒模型</title>
  6. <style>
  7. .box {height: 100px; border: 10px solid #000; font-size: 20px; color: #fff; padding: 10px; display: -webkit-box; -webkit-box-orient: horizontal; }
  8. .box div {width: 100px; height: 100px; background: red; border: 1px solid #fff;}
  9. /* .box div:nth-of-type(1){-webkit-box-ordinal-group:2;}
  10. .box div:nth-of-type(2){-webkit-box-ordinal-group:4;}
  11. .box div:nth-of-type(3){-webkit-box-ordinal-group:1;}
  12. .box div:nth-of-type(4){-webkit-box-ordinal-group:5;}
  13. .box div:nth-of-type(5){-webkit-box-ordinal-group:3;} */
  14. .box div:nth-of-type(1){width: 300px;}
  15. .box div:nth-of-type(2){-webkit-box-flex:2;}
  16. .box div:nth-of-type(3){-webkit-box-flex:3;}
  17. .box div:nth-of-type(4){-webkit-box-flex:4;}
  18. .box div:nth-of-type(5){-webkit-box-flex:5;}
  19. </style>
  20. </head>
  21. <body>
  22. <div class="box">
  23. <div>1</div>
  24. <div>2</div>
  25. <div>3</div>
  26. <div>4</div>
  27. <div>5</div>
  28. </div>
  29. </body>
  30. </html>
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>弹性盒模型</title>
  6. <style>
  7. .box {height: 200px; border: 10px solid #000; font-size: 20px; color: #fff; padding: 10px; display: -webkit-box; -webkit-box-orient: horizontal; -webkit-box-direction: reverse; -webkit-box-pack: justify; -webkit-box-align: end;}
  8. .box div {width: 100px; height: 100px; background: red; border: 1px solid #fff;}
  9. </style>
  10. </head>
  11. <body>
  12. <div class="box">
  13. <div>1</div>
  14. <div>2</div>
  15. <div>3</div>
  16. <div>4</div>
  17. <div>5</div>
  18. </div>
  19. </body>
  20. </html>

盒模型新增属性

盒模型阴影

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>盒模型阴影</title>
  6. <style>
  7. .box {width: 100px; height: 100px; margin: 100px; background: red; box-shadow: 0 0 30px 30px #000, inset 0 0 30px yellow;}
  8. </style>
  9. </head>
  10. <body>
  11. <div class="box"></div>
  12. </body>
  13. </html>

box-reflect 倒影

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>box-reflect 倒影</title>
  6. <style>
  7. img {display: block; margin: 30px auto; -webkit-box-reflect: below 10px -webkit-linear-gradient(bottom, rgba(0, 0, 0, 1) 0, rgba(0, 0, 0, 0) 70%)}
  8. </style>
  9. </head>
  10. <body>
  11. <img src="images/Green Nature Wallpapers 10.jpg" width="400">
  12. </body>
  13. </html>

resize 自由缩放

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>resize 自由缩放</title>
  6. <style>
  7. .box {width: 100px; height: 100px; background: url('images/Green Nature Wallpapers 10.jpg'); border: 5px solid red; resize: both; overflow: auto;}
  8. </style>
  9. </head>
  10. <body>
  11. <div class="box"></div>
  12. </body>
  13. </html>

box-sizing 盒模型解析模式

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>box-sizing</title>
  6. <style>
  7. .box {width: 200px; height: 200px; padding: 50px; border: 10px solid #000; box-sizing: border-box;}
  8. .div {height: 50px; background: red;}
  9. </style>
  10. </head>
  11. <body>
  12. <div class="box">
  13. <div class="div"></div>
  14. </div>
  15. </body>
  16. </html>

CSS3分栏布局

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>分栏布局</title>
  6. <style>
  7. /* .wrap {width: 900px; border: 1px solid #000; font: 14px/28px "宋体"; color: #000; text-indent: 2em; -webkit-column-width: 250px;} */
  8. .wrap {width: 900px; border: 1px solid #000; font: 14px/28px "宋体"; color: #000; text-indent: 2em; -webkit-column-count: 4; -webkit-column-gap: 30px; -webkit-column-rule: 1px dashed red;}
  9. </style>
  10. </head>
  11. <body>
  12. <div class="wrap">
  13. <p>按校科研处部署,我社2014年科研工作量统计工作安排如下:1. 申报者按要求如实填写《个人科研工作量计分表(2014)》(附件1)。2. 成果计分方法和科研工作量考核指标请参照《上海外国语大学科研工作量化标准与奖惩办法》(附件2)。成果奖励标准请参照《上海外国语大学优秀科</p>
  14. <p>按校科研处部署,我社2014年科研工作量统计工作安排如下:1. 申报者按要求如实填写《个人科研工作量计分表(2014)》(附件1)。2. 成果计分方法和科研工作量考核指标请参照《上海外国语大学科研工作量化标准与奖惩办法》(附件2)。成果奖励标准请参照《上海外国语大学优秀科</p>
  15. <p>按校科研处部署,我社2014年科研工作量统计工作安排如下:1. 申报者按要求如实填写《个人科研工作量计分表(2014)》(附件1)。2. 成果计分方法和科研工作量考核指标请参照《上海外国语大学科研工作量化标准与奖惩办法》(附件2)。成果奖励标准请参照《上海外国语大学优秀科</p>
  16. <p>按校科研处部署,我社2014年科研工作量统计工作安排如下:1. 申报者按要求如实填写《个人科研工作量计分表(2014)》(附件1)。2. 成果计分方法和科研工作量考核指标请参照《上海外国语大学科研工作量化标准与奖惩办法》(附件2)。成果奖励标准请参照《上海外国语大学优秀科</p>
  17. <p>按校科研处部署,我社2014年科研工作量统计工作安排如下:1. 申报者按要求如实填写《个人科研工作量计分表(2014)》(附件1)。2. 成果计分方法和科研工作量考核指标请参照《上海外国语大学科研工作量化标准与奖惩办法》(附件2)。成果奖励标准请参照《上海外国语大学优秀科</p>
  18. <p>按校科研处部署,我社2014年科研工作量统计工作安排如下:1. 申报者按要求如实填写《个人科研工作量计分表(2014)》(附件1)。2. 成果计分方法和科研工作量考核指标请参照《上海外国语大学科研工作量化标准与奖惩办法》(附件2)。成果奖励标准请参照《上海外国语大学优秀科</p>
  19. <p>按校科研处部署,我社2014年科研工作量统计工作安排如下:1. 申报者按要求如实填写《个人科研工作量计分表(2014)》(附件1)。2. 成果计分方法和科研工作量考核指标请参照《上海外国语大学科研工作量化标准与奖惩办法》(附件2)。成果奖励标准请参照《上海外国语大学优秀科</p>
  20. <p>按校科研处部署,我社2014年科研工作量统计工作安排如下:1. 申报者按要求如实填写《个人科研工作量计分表(2014)》(附件1)。2. 成果计分方法和科研工作量考核指标请参照《上海外国语大学科研工作量化标准与奖惩办法》(附件2)。成果奖励标准请参照《上海外国语大学优秀科</p>
  21. </div>
  22. </body>
  23. </html>

CSS3响应式布局

移动端meta

圆角

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>圆角</title>
  6. <style>
  7. /* .box {width: 200px; height: 200px; border: 1px solid #000; border-radius: 20px;} */
  8. /* .box {width: 200px; height: 200px; border: 1px solid #000; border-radius: 20px 40px;} */
  9. /* .box {width: 200px; height: 200px; border: 1px solid #000; border-radius: 20px 40px 60px;} */
  10. .box {width: 200px; height: 200px; border: 1px solid #000; border-radius: 20px 40px 60px 80px;}
  11. </style>
  12. </head>
  13. <body>
  14. <div class="box"></div>
  15. </body>
  16. </html>
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>圆角</title>
  6. <style>
  7. /* .box {width: 200px; height: 300px; border: 1px solid #000; border-radius: 100px/150px;} */ /*X轴半径/y轴半径*/
  8. .box {width: 200px; height: 300px; border: 1px solid #000; border-radius: 20px 40px 60px 80px/10px 20px 30px 40px;}
  9. </style>
  10. </head>
  11. <body>
  12. <div class="box"></div>
  13. </body>
  14. </html>
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>圆角</title>
  6. <style>.box {width: 200px; height: 300px; border: 1px solid #000; border-radius: 50%;}
  7. </style>
  8. </head>
  9. <body>
  10. <div class="box"></div>
  11. </body>
  12. </html>
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>圆角</title>
  6. <style>
  7. .box {width: 400px; height: 400px; margin: 50px auto; transition: 5s linear;}
  8. .box div {width: 180px; height: 180px; margin: 10px; border: 1px solid #000; box-sizing: border-box; float: left; background: url('images/Green Nature Wallpapers 10.jpg') no-repeat;}
  9. .box div:nth-child(1), .box div:nth-child(4) {border-radius: 0 70%;}
  10. .box div:nth-child(2), .box div:nth-child(3) {border-radius: 70% 0;}
  11. .box:hover {-webkit-transform: rotate(720deg);}
  12. </style>
  13. </head>
  14. <body>
  15. <div class="box">
  16. <div></div>
  17. <div></div>
  18. <div></div>
  19. <div></div>
  20. </div>
  21. </body>
  22. </html>

边框

线性渐变

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>线性渐变</title>
  6. <style>
  7. /* .box {width: 300px; height: 300px; border: 10px solid #000; background-image: -webkit-linear-gradient(left top, red, blue);} */
  8. /* .box {width: 300px; height: 300px; border: 10px solid #000; background-image: -webkit-linear-gradient(30deg, red, blue, yellow, green);} */
  9. /* .box {width: 300px; height: 300px; border: 10px solid #000; background-image: -webkit-linear-gradient(30deg, red 30px, blue 100px);} */
  10. /* .box {width: 300px; height: 300px; border: 10px solid #000; background-image: -webkit-linear-gradient(30deg, red 0, blue 50%, green 100%);} */
  11. .box {width: 300px; height: 300px; border: 10px solid #000; background-image: -webkit-repeating-linear-gradient(30deg, red 0, blue 30px);}
  12. </style>
  13. </head>
  14. <body>
  15. <div class="box"></div>
  16. </body>
  17. </html>
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>线性渐变</title>
  6. <style>
  7. .wrap {width: 200px; height: 30px; overflow: hidden; border: 1px solid #000;}
  8. .box {width: 400px; height: 30px; background: -webkit-repeating-linear-gradient(15deg, green 0, green 10px, #fff 10px, #fff 20px); transition: 3s linear;}
  9. .wrap:hover .box {margin-left: -100px;}
  10. </style>
  11. </head>
  12. <body>
  13. <div class="wrap">
  14. <div class="box"></div>
  15. </div>
  16. </body>
  17. </html>
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>线性渐变</title>
  6. <style>
  7. .box {width: 300px; height: 300px; background: url(img/ppt.gif) no-repeat, url(images/1.png) repeat-y right 0;}
  8. </style>
  9. </head>
  10. <body>
  11. <div class="box"></div>
  12. </body>
  13. </html>

百度音乐图片光影效果

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>线性渐变</title>
  6. <style>
  7. .box {width: 300px; height: 300px; background: -webkit-linear-gradient(-30deg, rgba(255, 255, 255, 0) 0, rgba(255, 255, 255, 0) 155px, rgba(255, 255, 255, 0.9) 170px, rgba(255, 255, 255, 0.9) 180px, rgba(255, 255, 255, 0) 200px) no-repeat -190px, url('images/Green Nature Wallpapers 10.jpg') no-repeat; transition: 1s;}
  8. .box:hover {background-position: 300px 0, 0 0;}
  9. </style>
  10. </head>
  11. <body>
  12. <div class="box"></div>
  13. </body>
  14. </html>

线性渐变——IE兼容

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>线性渐变——IE兼容</title>
  6. <style>
  7. .box {width: 300px; height: 300px; background: -webkit-linear-gradient(red, blue); background: -moz-linear-gradient(red, blue); background: linear-gradient(red, blue); filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='red',endColorstr='blue',GradientType='0');}
  8. </style>
  9. </head>
  10. <body>
  11. <div class="box"></div>
  12. </body>
  13. </html>

径向渐变

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>径向渐变</title>
  6. <style>
  7. .box {width: 300px; height: 300px; border: 1px solid #000; float: left; margin: 10px;}
  8. .box:nth-child(1) {background: -webkit-radial-gradient(100px 50px, closest-side, red, blue);}
  9. .box:nth-child(2) {background: -webkit-radial-gradient(100px 50px, closest-corner, red, blue);}
  10. .box:nth-child(3) {background: -webkit-radial-gradient(100px 50px, farthest-side, red, blue);}
  11. .box:nth-child(4) {background: -webkit-radial-gradient(100px 50px, farthest-corner, red, blue);}
  12. .box:nth-child(5) {background: -webkit-radial-gradient(100px 50px, contain, red, blue);}
  13. .box:nth-child(6) {background: -webkit-radial-gradient(100px 50px, cover, red, blue);}
  14. </style>
  15. </head>
  16. <body>
  17. <div class="box"></div>
  18. <div class="box"></div>
  19. <div class="box"></div>
  20. <div class="box"></div>
  21. <div class="box"></div>
  22. <div class="box"></div>
  23. </body>
  24. </html>

背景

iphone开机动画

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>iphone开机动画</title>
  6. <style>
  7. body {background: #000; text-align: center; font: 50px/200px "微软雅黑";}
  8. h1 {display: inline-block; color: rgba(255, 255, 255, 0.3); background: -webkit-linear-gradient(-30deg, rgba(255, 255, 255, 0) 100px, rgba(255, 255, 255, 1) 180px, rgba(255, 255, 255, 1) 240px, rgba(255, 255, 255, 0) 300px) no-repeat -300px; -webkit-background-clip: text;}
  9. </style>
  10. <script>
  11. window.onload = function(){
  12. var oH1 = document.getElementsByTagName('h1')[0];
  13. var oTimer = null;
  14. var iLeft = -300;
  15. function toMove(){
  16. oTimer = setInterval(function(){
  17. iLeft+=10;
  18. if(iLeft == 1000){
  19. iLeft = -300;
  20. clearInterval(oTimer);
  21. }
  22. oH1.style.backgroundPosition = iLeft + 'px 0px';
  23. }, 20)
  24. }
  25. setInterval(function(){
  26. toMove();
  27. }, 4000)
  28. }
  29. </script>
  30. </head>
  31. <body>
  32. <h1>MiaoV妙味课堂</h1>
  33. </body>
  34. </html>

遮罩

transition过渡

transition的基本操作

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>transition</title>
  6. <style>
  7. .box {width: 100px; height: 100px; background: red;}
  8. /* .box {transition: 1s;} */
  9. /*.box {transition: 500ms width;}*/
  10. /*.box {transition: 1s all;}*/
  11. /*.box {transition: 3s width ease;}*/
  12. /*.box {transition: 3s width ease-in-out;}*/
  13. /*.box {transition: 3s width cubic-bezier(0.930, 0.415, 0.000, 1.610);}*/
  14. /* .box {transition: 1s width, 2s height, 3s background;} */ /*多样式过渡*/
  15. /*.box {transition: 1s width, 2s 1s height, 3s 3s background;}*/ /*延迟过渡*/
  16. .box:hover {background: blue; width: 500px; height: 300px;}
  17. </style>
  18. <script>
  19. </script>
  20. </head>
  21. <body>
  22. <div class="box"></div>
  23. </body>
  24. </html>

过渡完成的事件以及问题一

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>transition</title>
  6. <style>
  7. .box {width: 100px; height: 100px; background: red; transition: 1s width, 2s height;}
  8. </style>
  9. <script>
  10. </script>
  11. </head>
  12. <body>
  13. <div class="box" id="box"></div>
  14. <script>
  15. var oBox = document.getElementById('box');
  16. //用transitionend事件,每个属性改变完一次就会触发一次
  17. oBox.onclick = function(){
  18. this.style.width = this.offsetWidth + 100 + 'px';
  19. this.style.height = this.offsetHeight + 100 + 'px';
  20. }
  21. addEnd(oBox, function(){
  22. alert('end');
  23. });
  24. function addEnd(obj, fn){
  25. obj.addEventListener('webkitTransitionEnd', fn, false);
  26. obj.addEventListener('transitionend', fn, false);
  27. }
  28. </script>
  29. </body>
  30. </html>

过渡完成的事件以及问题二

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>transition</title>
  6. <style>
  7. .box {width: 100px; height: 100px; background: red; transition: 1s width}
  8. </style>
  9. <script>
  10. </script>
  11. </head>
  12. <body>
  13. <div class="box" id="box"></div>
  14. <script>
  15. var oBox = document.getElementById('box');
  16. oBox.onclick = function(){
  17. this.style.width = this.offsetWidth + 100 + 'px';
  18. }
  19. //transitonend之后,又改变属性,接着又触发了transition就形成了循环
  20. addEnd(oBox, function(){
  21. this.style.width = this.offsetWidth + 100 + 'px';
  22. });
  23. function addEnd(obj, fn){
  24. obj.addEventListener('webkitTransitionEnd', fn, false);
  25. obj.addEventListener('transitionend', fn, false);
  26. }
  27. </script>
  28. </body>
  29. </html>

过渡完成事件问题二的处理方法

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>transition</title>
  6. <style>
  7. .box {width: 100px; height: 100px; background: red; transition: 1s width}
  8. </style>
  9. <script>
  10. </script>
  11. </head>
  12. <body>
  13. <div class="box" id="box"></div>
  14. <script>
  15. var oBox = document.getElementById('box');
  16. oBox.onclick = function(){
  17. this.style.width = this.offsetWidth + 100 + 'px';
  18. addEnd(oBox, end);
  19. }
  20. function end(){
  21. this.style.width = this.offsetWidth + 100 + 'px';
  22. removeEnd(this, end);
  23. }
  24. function addEnd(obj, fn){
  25. obj.addEventListener('webkitTransitionEnd', fn, false);
  26. obj.addEventListener('transitionend', fn, false);
  27. }
  28. function removeEnd(obj, fn){
  29. obj.removeEventListener('webkitTransitionEnd', fn, false);
  30. obj.removeEventListener('transitionend', fn, false);
  31. }
  32. </script>
  33. </body>
  34. </html>

2D变换

旋转

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>旋转</title>
  6. <style>
  7. body {height: 400px; border: 1px solid #000;}
  8. .box {width: 100px; height: 100px; background: red; margin:100px auto 0; transition: 2s;}
  9. body:hover .box {-webkit-transform: rotate(30deg); -moz-transform: rotate(30deg);}
  10. </style>
  11. <script>
  12. </script>
  13. </head>
  14. <body>
  15. <div class="box" id="box">123</div>
  16. </body>
  17. </html>

斜切

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>斜切</title>
  6. <style>
  7. body {height: 400px; border: 1px solid #000;}
  8. .box {width: 100px; height: 100px; background: red; margin:100px auto 0; transition: 2s;}
  9. /* body:hover .box {-webkit-transform: skewX(45deg); -moz-transform: skewX(45deg);} */
  10. /* body:hover .box {-webkit-transform: skewY(45deg); -moz-transform: skewY(45deg);} */
  11. body:hover .box {-webkit-transform: skew(15deg, 30deg); -moz-transform: skew(15deg, 30deg);}
  12. </style>
  13. <script>
  14. </script>
  15. </head>
  16. <body>
  17. <div class="box" id="box">123</div>
  18. </body>
  19. </html>

怪异导航

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>怪异导航</title>
  6. <style>
  7. ul {margin: 0; padding: 0; list-style: none;}
  8. li {float: left; width: 100px; text-align: center; height: 30px; border: 1px solid #fff; background: red; font: 12px/30px "宋体"; -moz-transform: skewX(30deg); -webkit-transform: skewX(30deg);}
  9. a {display: block; text-decoration: none; -moz-transform: skewX(-30deg); -webkit-transform: skewX(-30deg);}
  10. </style>
  11. </head>
  12. <body>
  13. <ul>
  14. <li><a href="#">妙味课堂</a></li>
  15. <li><a href="#">妙味茶馆</a></li>
  16. </ul>
  17. </body>
  18. </html>

缩放

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>缩放</title>
  6. <style>
  7. body {height: 400px; border: 1px solid #000;}
  8. .box {width: 100px; height: 100px; background: red; margin: 100px auto 0; transition: 2s;}
  9. /* body:hover .box {-webkit-transform: scaleX(0.5); -moz-transform: scaleX(0.5);} */
  10. body:hover .box {-webkit-transform: scale(0.5, -2); -moz-transform: scale(0.5, -2);}
  11. </style>
  12. </head>
  13. <body>
  14. <div class="box">123</div>
  15. </body>
  16. </html>

位移

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>位移</title>
  6. <style>
  7. body {height: 400px; border: 1px solid #000;}
  8. .box {width: 100px; height: 100px; background: red; margin: 100px auto 0; transition: 2s;}
  9. /* body:hover .box {-webkit-transform: translateX(100px); -moz-transform: translateX(100px);} */
  10. body:hover .box {-webkit-transform: translate(100px, -20px); -moz-transform: translate(100px, -20px);}
  11. </style>
  12. </head>
  13. <body>
  14. <div class="box">123</div>
  15. </body>
  16. </html>

transform的基点

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>transform的基点</title>
  6. <style>
  7. /* body {height: 300px; border: 1px solid #000;}
  8. .box {width: 100px; height: 100px; background: red; margin: 100px auto; transition: 5s; -webkit-transform-origin: right top; -moz-transform-origin: right top;} */
  9. body {height: 300px; border: 1px solid #000;}
  10. .box {width: 100px; height: 100px; background: red; margin: 100px auto; transition: 5s; -webkit-transform-origin: 10px 20px; -moz-transform-origin: 10px 20px;} /*transform-origin: 0 0; 如果是0 0就是左上角*/
  11. body:hover .box {-webkit-transform: rotate(360deg) scale(0.2); -moz-transform: rotate(360deg) scale(0.2);}
  12. </style>
  13. </head>
  14. <body>
  15. <div class="box"></div>
  16. </body>
  17. </html>

transform执行顺序问题

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>transform的执行顺序问题</title>
  6. <style>
  7. body {height: 300px; border: 1px solid #000;}
  8. .box {width: 100px; height: 100px; background: red; margin: 10px; transition: 1s;}
  9. body:hover .box:nth-of-type(1) {-webkit-transform: translateX(100px) scale(0.5); -moz-transform: translateX(100px) scale(0.5);}
  10. body:hover .box:nth-of-type(2) {-webkit-transform: scale(0.5) translateX(100px); -moz-transform: scale(0.5) translateX(100px); }/*第二个div的变化,scale在前,translate在后。后写的限制性,就是先位移再缩放,那么位移设置的100也被缩放了0.5,因此实际只位移了50px*/
  11. </style>
  12. </head>
  13. <body>
  14. <div class="box">111</div>
  15. <div class="box">222</div>
  16. </body>
  17. </html>

钟表效果

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>钟表效果</title>
  6. <style id="css">
  7. #wrap {width: 200px; height: 200px; border: 2px solid #000; margin: 100px auto; border-radius: 50%; position: relative;}
  8. #wrap ul {margin: 0; padding: 0; height: 200px; position: relative; list-style: none;}
  9. #wrap ul li {width: 2px; height: 6px; background: #000; position: absolute; left: 99px; top: 0; -webkit-transform-origin: center 100px; -moz-transform-origin: center 100px;}
  10. /* #wrap ul li:nth-of-type(1) {-webkit-transform: rotate(0); -moz-transform: rotate(0);}
  11. #wrap ul li:nth-of-type(2) {-webkit-transform: rotate(6deg); -moz-transform: rotate(6deg);}
  12. #wrap ul li:nth-of-type(3) {-webkit-transform: rotate(12deg); -moz-transform: rotate(12deg);}
  13. #wrap ul li:nth-of-type(4) {-webkit-transform: rotate(18deg); -moz-transform: rotate(18deg);}
  14. #wrap ul li:nth-of-type(5) {-webkit-transform: rotate(24deg); -moz-transform: rotate(24deg);}
  15. #wrap ul li:nth-of-type(6) {-webkit-transform: rotate(30deg); -moz-transform: rotate(30deg);}
  16. #wrap ul li:nth-of-type(7) {-webkit-transform: rotate(36deg); -moz-transform: rotate(36deg);}
  17. #wrap ul li:nth-of-type(8) {-webkit-transform: rotate(42deg); -moz-transform: rotate(42deg);} */
  18. #wrap ul li:nth-of-type(5n+1) {height: 12px;}
  19. #hour {width: 6px; height: 45px; background: #000; position: absolute; left: 97px; top: 55px; -webkit-transform-origin: bottom; -moz-transform-origin: bottom;}
  20. #min {width: 4px; height: 65px; background: #999; position: absolute; left: 98px; top: 35px; -webkit-transform-origin: bottom; -moz-transform-origin: bottom;}
  21. #sec {width: 2px; height: 80px; background: red; position: absolute; left: 99px; top: 20px; -webkit-transform-origin: bottom; -moz-transform-origin: bottom;}
  22. .ico {width: 20px; height: 20px; background: #000; border-radius: 50%; position: absolute; left: 90px; top: 90px;}
  23. </style>
  24. </head>
  25. <body>
  26. <div id="wrap">
  27. <ul id="ul1">
  28. <!-- <li></li>
  29. <li></li>
  30. <li></li>
  31. <li></li>
  32. <li></li>
  33. <li></li>
  34. <li></li>
  35. <li></li> -->
  36. </ul>
  37. <div id="hour"></div>
  38. <div id="min"></div>
  39. <div id="sec"></div>
  40. <div class="ico"></div>
  41. </div>
  42. <script>
  43. var oList = document.getElementById('ul1');
  44. var oCss = document.getElementById('css');
  45. var oHour = document.getElementById('hour');
  46. var oMin = document.getElementById('min');
  47. var oSec = document.getElementById('sec');
  48. var aLi = '';
  49. var sCss = '';
  50. for(var i=0; i<60; i++){
  51. sCss += '#wrap ul li:nth-of-type(' + (i+1) + ') {-webkit-transform: rotate(' + i*6 + 'deg); -moz-transform: rotate(' + i*6 + 'deg);}'
  52. aLi += '<li></li>'
  53. }
  54. oList.innerHTML = aLi;
  55. oCss.innerHTML += sCss;
  56. toTime();
  57. setInterval(toTime, 1000);
  58. function toTime(){
  59. var oDate = new Date();
  60. var iSec = oDate.getSeconds();
  61. var iMin = oDate.getMinutes() + iSec/60;
  62. var iHour = oDate.getHours() + iMin/60;
  63. oSec.style.WebkitTransform = 'rotate(' + iSec *6 + 'deg)';
  64. oSec.style.MozTransform = 'rotate(' + iSec *6 + 'deg)';
  65. oMin.style.WebkitTransform = 'rotate(' + iMin *6 + 'deg)';
  66. oMin.style.MozTransform = 'rotate(' + iMin *6 + 'deg)';
  67. oHour.style.WebkitTransform = 'rotate(' + iHour *30 + 'deg)';
  68. oHour.style.MozTransform = 'rotate(' + iHour *30 + 'deg)';
  69. }
  70. </script>
  71. </body>
  72. </html>

扇形导航

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>无标题文档</title>
  6. <style>
  7. body{ background:#f9f9f9;}
  8. #menu{width:50px;height:50px; position:fixed;right:20px; bottom:20px; }
  9. #menu_list{height:42px;width:42px; position:relative;margin:4px;}
  10. #menu_list img{ border-radius:21px; position:absolute;left:0;top:0; -webkit-transition:0.5s all ease;}
  11. #home{width:50px;height:50px;background:url(home.png) no-repeat; border-radius:25px; position:absolute; left:0;top:0; transition:1s;}
  12. </style>
  13. <script>
  14. window.onload=function()
  15. {
  16. var oHome=document.getElementById("home");
  17. var aImg=document.getElementById("menu_list").getElementsByTagName("img");
  18. var bOff=true;
  19. var iR=-150;
  20. for(var i=0;i<aImg.length;i++)
  21. {
  22. aImg[i].onclick=function()
  23. {
  24. this.style.transition="0.3s";
  25. this.style.WebkitTransform="scale(2) rotate(-720deg)";
  26. this.style.opacity=0.1;
  27. addEnd(this,end);
  28. };
  29. }
  30. function end()
  31. {
  32. this.style.transition="0.1s";
  33. this.style.WebkitTransform="scale(1) rotate(-720deg)";
  34. this.style.opacity=1;
  35. removeEnd(this,end);
  36. }
  37. oHome.onclick=function()
  38. {
  39. if(bOff)
  40. {
  41. this.style.WebkitTransform="rotate(-360deg)";
  42. for(var i=0;i<aImg.length;i++)
  43. {
  44. var oLt=toLT(iR,90/4*i);
  45. aImg[i].style.transition="0.5s "+i*100+"ms";
  46. aImg[i].style.left=oLt.l+"px";
  47. aImg[i].style.top=oLt.t+"px";
  48. aImg[i].style.WebkitTransform="scale(1) rotate(-720deg)";
  49. }
  50. }
  51. else
  52. {
  53. this.style.WebkitTransform="rotate(0deg)";
  54. for(var i=0;i<aImg.length;i++)
  55. {
  56. aImg[i].style.transition="0.5s "+(aImg.length-i-1)*100+"ms";
  57. aImg[i].style.left=0+"px";
  58. aImg[i].style.top=0+"px";
  59. aImg[i].style.WebkitTransform="scale(1) rotate(0deg)";
  60. }
  61. }
  62. bOff=!bOff;
  63. };
  64. };
  65. function toLT(iR,iDeg)
  66. {
  67. return {l:Math.round(Math.sin(iDeg/180*Math.PI)*iR),t:Math.round(Math.cos(iDeg/180*Math.PI)*iR)}
  68. }
  69. function addEnd(obj,fn)
  70. {
  71. obj.addEventListener('WebkitTransitionEnd',fn,false);
  72. obj.addEventListener('transitionend',fn,false);
  73. }
  74. function removeEnd(obj,fn)
  75. {
  76. obj.removeEventListener('WebkitTransitionEnd',fn,false);
  77. obj.removeEventListener('transitionend',fn,false);
  78. }
  79. /*
  80. 已知直角三角形的斜边长度和夹角 求对边(sin)和临边的长度
  81. */
  82. </script>
  83. </head>
  84. <body>
  85. <div id="menu">
  86. <div id="menu_list">
  87. <img src="prev.png" alt=""/>
  88. <img src="open.png" alt="" />
  89. <img src="clos.png" alt="" />
  90. <img src="full.png" alt="" />
  91. <img src="refresh.png" alt="" />
  92. </div>
  93. <div id="home"></div>
  94. </div>
  95. </body>
  96. </html>

Matrix矩阵

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>2d变换——Matrix矩阵</title>
  6. <style>
  7. .box {width: 100px; height: 100px; background: red; transition: 1s;}
  8. .box:hover {-webkit-transform: matrix(0.5,0.38,-0.38,2,0,0); -moz-transform: matrix(0.5,0.38,-0.38,2,0,0);}
  9. /*
  10. 标准浏览器:
  11. matrix(1,0,0,1,0,0) 默认情况
  12. matrix(a,b,c,d,e,f) 六个参数
  13. IE浏览器:
  14. filter: progid:DXImageTransform.Microsoft.Matrix(M11=1, M12=0, M21=0, M22=1, SizingMethod='auto expand');
  15. Matrix(M11==a, M12==c, M21==b, M22==d) 只有四个参数,而且顺序与标准下不同
  16. */
  17. </style>
  18. </head>
  19. <body>
  20. <div class="box"></div>
  21. </body>
  22. </html>

通过矩阵Mathix实现位移

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>通过矩阵Matrix实现位移</title>
  6. <style>
  7. /*
  8. matrix(a,b,c,d,e,f) 六个参数
  9. 位移:两个方向
  10. x: 参数e代表x轴的位移 e+disX
  11. y: 参数f代表y轴的位移 f+disY
  12. IE下没有e、f两个参数,因此无法直接实现位移,但是可以用定位来替换实现效果
  13. */
  14. body {height: 300px; border: 1px solid #000;}
  15. .box {width: 100px; height: 100px; background: red; transition: 1s;}
  16. body:hover .box {-webkit-transform: matrix(1,0,0,1,100,300); -moz-transform: matrix(1,0,0,1,100,300);}
  17. </style>
  18. </head>
  19. <body>
  20. <div class="box"></div>
  21. </body>
  22. </html>

通过矩阵Mathix实现缩放

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>通过矩阵Matrix实现缩放</title>
  6. <style>
  7. /*
  8. matrix(a,b,c,d,e,f) 六个参数
  9. 缩放:
  10. x轴缩放 a=x*a c=x*c e=x*e
  11. y轴缩放 b=y*b d=y*d f=y*f
  12. */
  13. body {height: 300px; border: 1px solid #000;}
  14. .box {width: 100px; height: 100px; background: red; transition: 1s;}
  15. </style>
  16. </head>
  17. <body>
  18. <div class="box" id="box"></div>
  19. <script>
  20. var oBox = document.getElementById('box');
  21. oBox.onclick = function(){
  22. oBox.style.WebkitTransform = 'matrix(0.5,0,0,0.2,0,0)';
  23. oBox.style.MozTransform = 'matrix(0.5,0,0,0.2,0,0)';
  24. oBox.style.transform = 'matrix(0.5,0,0,0.2,0,0)';
  25. oBox.style.filter = 'progid:DXImageTransform.Microsoft.Matrix(M11=0.5, M12=0, M21=0, M22=0.2, SizingMethod="auto expand")';
  26. }
  27. </script>
  28. </body>
  29. </html>

通过矩阵Mathix实现倾斜

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>通过矩阵Matrix实现倾斜</title>
  6. <style>
  7. /*
  8. matrix(a,b,c,d,e,f) 六个参数
  9. 倾斜:
  10. x轴倾斜 c=Math.tan(xDeg/180*Math.PI)
  11. y轴倾斜 b=Math.tan(yDeg/180*Math.PI)
  12. */
  13. body {height: 300px; border: 1px solid #000;}
  14. .box {width: 100px; height: 100px; background: red; transition: 1s;}
  15. </style>
  16. </head>
  17. <body>
  18. <div class="box" id="box"></div>
  19. <script>
  20. //Math.tan(30/180*Math.PI)约等于0.58
  21. var oBox = document.getElementById('box');
  22. oBox.onclick = function(){
  23. oBox.style.WebkitTransform = 'matrix(1,0, 0.58,1,0,0)';
  24. oBox.style.MozTransform = 'matrix(1,0,0.58,1,0,0)';
  25. oBox.style.transform = 'matrix(1,0,0.58,1,0,0)';
  26. oBox.style.filter = 'progid:DXImageTransform.Microsoft.Matrix(M11=1, M12=0.58, M21=0, M22=1, SizingMethod="auto expand")';
  27. }
  28. </script>
  29. </body>
  30. </html>

通过矩阵Matrix实现旋转

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>通过矩阵Matrix实现旋转</title>
  6. <style>
  7. /*
  8. matrix(a,b,c,d,e,f) 六个参数
  9. 旋转:
  10. a=Math.cos(deg/180*Math.PI);
  11. b=Math.sin(deg/180*Math.PI);
  12. c=-Math.sin(deg/180*Math.PI);
  13. d=Math.cos(deg/180*Math.PI);
  14. */
  15. body {height: 300px; border: 1px solid #000;}
  16. .box {width: 100px; height: 100px; background: red; transition: 1s;}
  17. </style>
  18. </head>
  19. <body>
  20. <div class="box" id="box"></div>
  21. <script>
  22. //Math.sin(30/180*Math.PI) 约为0.5
  23. //Math.cos(30/180*Math.PI) 约为0.87
  24. var oBox = document.getElementById('box');
  25. oBox.onclick = function(){
  26. oBox.style.WebkitTransform = 'matrix(0.87,0.5, -0.5,0.87,0,0)';
  27. oBox.style.MozTransform = 'matrix(0.87,0.5, -0.5,0.87,0,0)';
  28. oBox.style.transform = 'matrix(0.87,0.5, -0.5,0.87,0,0)';
  29. oBox.style.filter = 'progid:DXImageTransform.Microsoft.Matrix(M11=0.87, M12=0.5, M21=-0.5, M22=0.87, SizingMethod="auto expand")';
  30. // alert(this.offsetWidth);
  31. }
  32. </script>
  33. </body>
  34. </html>

IE下的基点修正

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>IE基点修正</title>
  6. <style>
  7. .box {width: 100px; height: 100px; margin: 30px auto; position: relative; border: 1px solid #000;}
  8. #box {width: 100px; height: 100px; background: red; position: absolute; left: 0; top: 0;}
  9. /*#box:hover {-webkit-transform: rotate(360deg); -moz-transform: rotate(360deg);}*/
  10. </style>
  11. </head>
  12. <body>
  13. <div class="box">
  14. <div id="box"></div>
  15. </div>
  16. <script>
  17. var oBox = document.getElementById('box');
  18. var iDeg = 0;
  19. setInterval(function(){
  20. iDeg++;
  21. toRotate(oBox, iDeg)
  22. }, 30)
  23. function toRotate(obj, iDeg){
  24. var a = Math.round(Math.cos(iDeg/180*Math.PI)*100)/100; //乘以100之后四舍五入,然后除以100
  25. var b = Math.round(Math.sin(iDeg/180*Math.PI)*100)/100;
  26. var c = -b;
  27. var d = a;
  28. obj.style.WebkitTransform = 'matrix(' + a + ',' + b + ', ' + c + ',' + d + ',0,0)';
  29. obj.style.MozTransform = 'matrix(' + a + ',' + b + ', ' + c + ',' + d + ',0,0)';
  30. obj.style.transform = 'matrix(' + a + ',' + b + ', ' + c + ',' + d + ',0,0)';
  31. obj.style.filter = 'progid:DXImageTransform.Microsoft.Matrix(M11=' + a + ', M12=' + c + ', M21=' + b + ', M22=' + d + ', SizingMethod="auto expand")';
  32. //下面两行修正IE下的基点问题
  33. obj.style.left = (obj.parentNode.offsetWidth-obj.offsetWidth)/2 + 'px';
  34. obj.style.top = (obj.parentNode.offsetHeight-obj.offsetHeight)/2 + 'px';
  35. }
  36. </script>
  37. </body>
  38. </html>

3d变换

3d旋转

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>3d变换</title>
  6. <style>
  7. .box {width: 100px; height: 100px; padding: 100px; border: 5px solid #000; margin: 30px auto; -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; -webkit-perspective: 100px; -moz-perspective: 100px;}
  8. .div {width: 100px; height: 100px; background: red; transition: 1s;}
  9. /* .box:hover .div {-webkit-transform: rotateX(180deg); -moz-transform: rotateX(180deg);} */
  10. .box:hover .div {-webkit-transform: rotateY(180deg); -moz-transform: rotateY(180deg);}
  11. /* .box:hover .div {-webkit-transform: rotateZ(180deg); -moz-transform: rotateZ(180deg);} */
  12. </style>
  13. </head>
  14. <body>
  15. <div class="box">
  16. <div class="div">111</div>
  17. </div>
  18. </body>
  19. </html>

3d的translateZ

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title>3d变换</title>
  6. <style>
  7. .box {width: 100px; height: 100px; padding: 100px; border: 5px solid #000; margin: 30px auto; -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; -webkit-perspective: 200px; -moz-perspective: 200px;}
  8. .div {width: 100px; height: 100px; background: red; transition: 1s;}
  9. .box:hover .div {-webkit-transform: translateZ(100px); -moz-transform: translateZ(100px);}
  10. </style>
  11. </head>
  12. <body>
  13. <div class="box">
  14. <div class="div">111</div>
  15. </div>
  16. </body>
  17. </html>

3d小盒子

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title></title>
  6. <style>
  7. .wrap {width: 100px; height: 100px; padding: 100px; border: 5px solid #000; margin: 100px auto; -webkit-perspective: 200px; -moz-perspective: 200px;}
  8. .box {width: 100px; height: 100px; background: red; position: relative; -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; transition: 2s; -webkit-transform-origin: center center -50px; -moz-transform-origin: center center -50px;}
  9. .box div {width: 100px; height: 100px; position: absolute; color: #fff; font-size: 50px; text-align: center; line-height: 100px;}
  10. .box div:nth-of-type(1) {left: 0; top: -100px; background: #9c0; -webkit-transform-origin: bottom; -moz-transform-origin: bottom; -webkit-transform: rotateX(90deg); -moz-transform: rotateX(90deg);}
  11. .box div:nth-of-type(2) {left: -100px; top: 0; background: #cf3; -webkit-transform-origin: right; -moz-transform-origin: right; -webkit-transform: rotateY(-90deg); -moz-transform: rotateY(-90deg);}
  12. .box div:nth-of-type(3) {left: 0; top: 0; background: #ccf;}
  13. .box div:nth-of-type(4) {left: 100px; top: 0; background: #0c9; -webkit-transform-origin: left; -moz-transform-origin: left; -webkit-transform: rotateY(90deg); -moz-transform: rotateY(90deg);}
  14. .box div:nth-of-type(5) {left: 0; top: 100px; background: #69c; -webkit-transform-origin: top; -moz-transform-origin: top; -webkit-transform: rotateX(-90deg); -moz-transform: rotateX(-90deg);}
  15. .box div:nth-of-type(6) {left: 0; top: 0; background: #f0c; -webkit-transform: translateZ(-100px) rotateX(180deg); -moz-transform: translateZ(-100px) rotateX(180deg); }
  16. .wrap:hover .box {-webkit-transform: rotateX(180deg); -moz-transform: rotateX(180deg);}
  17. </style>
  18. </head>
  19. <body>
  20. <div class="wrap">
  21. <div class="box">
  22. <div>1</div>
  23. <div>2</div>
  24. <div>3</div>
  25. <div>4</div>
  26. <div>5</div>
  27. <div>6</div>
  28. </div>
  29. </div>
  30. </body>
  31. </html>

景深基点

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <title></title>
  6. <style>
  7. .wrap {width: 100px; height: 100px; padding: 100px; border: 5px solid #000; margin: 100px auto; -webkit-perspective: 200px; -moz-perspective: 200px; -webkit-perspective-origin: left top; -moz-perspective-origin: left top;}
  8. .box {width: 100px; height: 100px; background: red; position: relative; -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; transition: 2s; -webkit-transform-origin: center center -50px; -moz-transform-origin: center center -50px;}
  9. .box div {width: 100px; height: 100px; position: absolute; color: #fff; font-size: 50px; text-align: center; line-height: 100px;}
  10. .box div:nth-of-type(1) {left: 0; top: -100px; background: #9c0; -webkit-transform-origin: bottom; -moz-transform-origin: bottom; -webkit-transform: rotateX(90deg); -moz-transform: rotateX(90deg);}
  11. .box div:nth-of-type(2) {left: -100px; top: 0; background: #cf3; -webkit-transform-origin: right; -moz-transform-origin: right; -webkit-transform: rotateY(-90deg); -moz-transform: rotateY(-90deg);}
  12. .box div:nth-of-type(3) {left: 0; top: 0; background: #ccf;}
  13. .box div:nth-of-type(4) {left: 100px; top: 0; background: #0c9; -webkit-transform-origin: left; -moz-transform-origin: left; -webkit-transform: rotateY(90deg); -moz-transform: rotateY(90deg);}
  14. .box div:nth-of-type(5) {left: 0; top: 100px; background: #69c; -webkit-transform-origin: top; -moz-transform-origin: top; -webkit-transform: rotateX(-90deg); -moz-transform: rotateX(-90deg);}
  15. .box div:nth-of-type(6) {left: 0; top: 0; background: #f0c; -webkit-transform: translateZ(-100px) rotateX(180deg); -moz-transform: translateZ(-100px) rotateX(180deg); }
  16. .wrap:hover .box {-webkit-transform: rotateX(180deg); -moz-transform: rotateX(180deg);}
  17. </style>
  18. </head>
  19. <body>
  20. <div class="wrap">
  21. <div class="box">
  22. <div>1</div>
  23. <div>2</div>
  24. <div>3</div>
  25. <div>4</div>
  26. <div>5</div>
  27. <div>6</div>
  28. </div>
  29. </div>
  30. </body>
  31. </html>

3d幻灯片

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>3d幻灯片</title>
  6. <style id="css">
  7. body, ul, ol {margin: 0; padding: 0;}
  8. li {list-style: none;}
  9. .wrap {width: 800px; margin: 100px auto 0;}
  10. #picList {width: 800px; height: 360px; -webkit-perspective: 800px; -moz-perspective: 800px;}
  11. #picList li {width: 20px; height: 360px; position: relative; -webkit-transform-style: preserve-3d; -moz-transform-style: preserve-3d; -webkit-transform-origin: center center -180px; -moz-transform-origin: center center -180px; float: left;}
  12. #picList li a {width: 100%; height: 100%; position: absolute; left: 0; top: 0;}
  13. #picList li a:nth-of-type(1) {background: url(img/1.jpg) no-repeat;}
  14. #picList li a:nth-of-type(2) {background: url(img/2.jpg) no-repeat; top: -360px; -webkit-transform-origin: bottom; -webkit-transform: rotateX(90deg); -moz-transform-origin: bottom; -moz-transform: rotateX(90deg);}
  15. #picList li a:nth-of-type(3) {background: url(img/3.jpg) no-repeat; -webkit-transform: translateZ(-360px) rotateX(180deg); -moz-transform: translateZ(-360px) rotateX(180deg);}
  16. #picList li a:nth-of-type(4) {background: url(img/4.jpg) no-repeat; top: 360px; -webkit-transform-origin: top; -webkit-transform: rotateX(-90deg); -moz-transform-origin: top; -moz-transform: rotateX(-90deg);}
  17. #picList li span {position: absolute; width: 360px; height: 360px; background: #333;}
  18. #picList li span:nth-of-type(1) {-moz-transform-origin: left; -moz-transform: rotateY(90deg); -webkit-transform-origin: left; -webkit-transform: rotateY(90deg); left: 0;}
  19. #picList li span:nth-of-type(2) {-moz-transform-origin: right; -moz-transform: rotateY(-90deg); -webkit-transform-origin: right; -webkit-transform: rotateY(-90deg); right: 0;}
  20. #btns {float: right; padding: 10px 0;}
  21. #btns li {width: 40px; height: 40px; background: #000; color: #fff; border-radius: 50%; font: italic 30px/40px Arial; float: left; margin: 0 5px; text-align: center; cursor: pointer;}
  22. #btns .active {background: orange;}
  23. /* #picList li:nth-of-type(1) a {background-position: 0 0;}
  24. #picList li:nth-of-type(2) a {background-position: -50px 0;}
  25. #picList li:nth-of-type(8) a {background-position: -350px 0;} */
  26. </style>
  27. <script>
  28. window.onload = function(){
  29. var oPicList = document.getElementById('picList');
  30. var oCss = document.getElementById('css');
  31. var aBtns = document.getElementById('btns').getElementsByTagName('li');
  32. var aLi = null;
  33. var sLi = "";
  34. var sCss = "";
  35. var iLiW = 20;
  36. var iZindex = 0;
  37. var iNow = 0;
  38. var iLength = oPicList.clientWidth / iLiW;
  39. for(var i=0; i<iLength; i++){
  40. i > iLength/2 ? iZindex-- : iZindex++;
  41. sLi += '<li><a href="#"></a><a href="#"></a><a href="#"></a><a href="#"></a><span></span><span></span></li>';
  42. sCss += '#picList li:nth-of-type(' + (i + 1) + ') a {background-position: -' + i*iLiW + 'px 0;}';
  43. sCss += '#picList li:nth-of-type(' + (i + 1) + ') {z-index:' + iZindex + '}';
  44. }
  45. oPicList.innerHTML = sLi;
  46. oCss.innerHTML += sCss;
  47. aLi = oPicList.children;
  48. for(var i=0; i<aBtns.length; i++){
  49. (function(a){
  50. aBtns[a].onclick = function(){
  51. for(var i=0; i<aLi.length; i++){
  52. aLi[i].style.transition = '0.5s ' + i*30 + 'ms';
  53. aLi[i].style.WebkitTransform = 'rotateX(-' + a*90 + 'deg)';
  54. aLi[i].style.MozTransform = 'rotateX(-' + a*90 + 'deg)';
  55. }
  56. this.className = 'active';
  57. aBtns[iNow].className = '';
  58. iNow = a;
  59. }
  60. })(i)
  61. }
  62. }
  63. </script>
  64. </head>
  65. <body>
  66. <div class="wrap">
  67. <ul id="picList">
  68. <!-- <li>
  69. <a href="#"></a>
  70. <a href="#"></a>
  71. <a href="#"></a>
  72. <a href="#"></a>
  73. <span></span>
  74. <span></span>
  75. </li> -->
  76. </ul>
  77. <ol id="btns">
  78. <li class="active">1</li>
  79. <li>2</li>
  80. <li>3</li>
  81. <li>4</li>
  82. </ol>
  83. </div>
  84. </body>
  85. </html>

animation

animation基本使用

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>animation</title>
  6. <style>
  7. @-webkit-keyframes move {
  8. 0% {
  9. width: 100px;
  10. }
  11. 50% {
  12. width: 1000px;
  13. }
  14. 100% {
  15. width: 500px;
  16. }
  17. }
  18. @-moz-keyframes move {
  19. 0% {
  20. width: 100px;
  21. }
  22. 50% {
  23. width: 1000px;
  24. }
  25. 100% {
  26. width: 500px;
  27. }
  28. }
  29. @keyframes move {
  30. 0% {
  31. width: 100px;
  32. }
  33. 50% {
  34. width: 1000px;
  35. }
  36. 100% {
  37. width: 500px;
  38. }
  39. }
  40. .box {width: 100px; height: 100px; background: red; -webkit-animation: 2s move; -moz-animation: 2s move; animation: 2s move;}
  41. </style>
  42. </head>
  43. <body>
  44. <div class="box"></div>
  45. </body>
  46. </html>

animate——调用动画

animation的其他参数使用

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>animation</title>
  6. <style>
  7. @-webkit-keyframes move {
  8. 50% {
  9. width: 1000px;
  10. }
  11. }
  12. .box {width: 100px; height: 100px; background: red; -webkit-animation: 1s 1s move ease-in infinite;}
  13. </style>
  14. </head>
  15. <body>
  16. <div class="box"></div>
  17. </body>
  18. </html>

走回字,支持动画暂停

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>走回字形</title>
  6. <style>
  7. @-webkit-keyframes doMove{
  8. 0% {
  9. top: 0; left: 0;
  10. }
  11. 25% {
  12. top: 0; left: 300px;
  13. }
  14. 50% {
  15. top: 300px; left: 300px;
  16. }
  17. 75% {
  18. top: 300px; left: 0;
  19. }
  20. 100% {
  21. top: 0; left: 0;
  22. }
  23. }
  24. #wrap {width: 400px; height: 400px; border: 5px solid #000; position: relative;}
  25. .box {width: 100px; height: 100px; background: red; position: absolute; left: 0; top: 0; -webkit-animation: 4s doMove linear infinite;}
  26. #wrap:hover .box {-webkit-animation-play-state: paused;}
  27. </style>
  28. </head>
  29. <body>
  30. <div id="wrap">
  31. <div class="box"></div>
  32. </div>
  33. </body>
  34. </html>

正序倒序播放

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>正序、倒序播放</title>
  6. <style>
  7. @-webkit-keyframes doMove{
  8. 0% {
  9. top: 0; left: 0;
  10. }
  11. 25% {
  12. top: 0; left: 300px;
  13. }
  14. 50% {
  15. top: 300px; left: 300px;
  16. }
  17. 75% {
  18. top: 300px; left: 0;
  19. }
  20. 100% {
  21. top: 0; left: 0;
  22. }
  23. }
  24. #wrap {width: 400px; height: 400px; border: 5px solid #000; position: relative;}
  25. .box {width: 100px; height: 100px; background: red; position: absolute; left: 0; top: 0; -webkit-animation: 4s doMove linear infinite alternate;}
  26. </style>
  27. </head>
  28. <body>
  29. <div id="wrap">
  30. <div class="box"></div>
  31. </div>
  32. </body>
  33. </html>

处理动画完毕之后回到默认样式的简单做法

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>animation</title>
  6. <style>
  7. @-webkit-keyframes move {
  8. 0% {
  9. width: 100px;
  10. }
  11. 100% {
  12. width: 500px;
  13. }
  14. }
  15. .box {width: 100px; height: 100px; background: red;}
  16. .move {-webkit-animation: 2s move; width: 500px;}
  17. </style>
  18. </head>
  19. <body>
  20. <div class="box move"></div>
  21. </body>
  22. </html>

动画结束保持原状,与js结合的做法

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>animation</title>
  6. <style>
  7. @-webkit-keyframes move {
  8. 0% {
  9. width: 100px;
  10. }
  11. 100% {
  12. width: 500px;
  13. }
  14. }
  15. .box {width: 100px; height: 100px; background: red;}
  16. .move {-webkit-animation: 2s move; width: 500px;}
  17. </style>
  18. </head>
  19. <body>
  20. <div class="box" id="box"></div>
  21. <script>
  22. document.getElementById('box').onclick = function(){
  23. this.className = 'box move';
  24. }
  25. </script>
  26. </body>
  27. </html>

animationend事件

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>animation</title>
  6. <style>
  7. @-webkit-keyframes move {
  8. 0% {
  9. width: 100px;
  10. }
  11. 100% {
  12. width: 500px;
  13. }
  14. }
  15. @-moz-keyframes move {
  16. 0% {
  17. width: 100px;
  18. }
  19. 100% {
  20. width: 500px;
  21. }
  22. }
  23. @keyframes move {
  24. 0% {
  25. width: 100px;
  26. }
  27. 100% {
  28. width: 500px;
  29. }
  30. }
  31. .box {width: 100px; height: 100px; background: red;}
  32. .move {-webkit-animation: 2s move; -moz-animation: 2s move; animation: 2s move; width: 500px;}
  33. </style>
  34. </head>
  35. <body>
  36. <div class="box" id="box"></div>
  37. <script>
  38. document.getElementById('box').onclick = function(){
  39. this.className = 'box move';
  40. addEnd(this, fn);
  41. }
  42. function fn(){
  43. alert('end');
  44. }
  45. function addEnd(obj, fn){
  46. obj.addEventListener('webkitAnimationEnd', fn, false);
  47. obj.addEventListener('animationend', fn, false);
  48. }
  49. </script>
  50. </body>
  51. </html>

无缝滚动

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>无缝滚动</title>
  6. <style>
  7. @-webkit-keyframes move {
  8. 0% {
  9. left: 0;
  10. }
  11. 100% {
  12. left: -500px;
  13. }
  14. }
  15. #wrap {width: 500px; height: 100px; border: 1px solid #000; position: relative; margin: 100px auto; overflow: hidden;}
  16. #list {position: absolute; left: 0; top: 0; margin: 0; padding: 0; -webkit-animation: 3s infinite move linear; width: 200%;}
  17. #list li {list-style: none; width: 98px; height: 98px; border: 1px solid #fff; background: #000; color: #fff; font: 50px/98px Arial; text-align: center; float: left;}
  18. #wrap:hover #list {-webkit-animation-play-state: paused;}
  19. </style>
  20. </head>
  21. <body>
  22. <div id="wrap">
  23. <ul id="list">
  24. <li>1</li>
  25. <li>2</li>
  26. <li>3</li>
  27. <li>4</li>
  28. <li>5</li>
  29. <li>1</li>
  30. <li>2</li>
  31. <li>3</li>
  32. <li>4</li>
  33. <li>5</li>
  34. </ul>
  35. </div>
  36. </body>
  37. </html>

3d图片轮换

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>3d图片轮换</title>
  6. <style>
  7. @-webkit-keyframes show {
  8. 0% {
  9. -webkit-transform: rotateX(180deg);
  10. opacity: 0;
  11. }
  12. 50%{
  13. -webkit-transform: rotateX(-20deg);
  14. opacity: 1;
  15. }
  16. 60%{
  17. -webkit-transform: rotateX(18deg);
  18. opacity: 1;
  19. }
  20. 70%{
  21. -webkit-transform: rotateX(-12deg);
  22. opacity: 1;
  23. }
  24. 80%{
  25. -webkit-transform: rotateX(8deg);
  26. opacity: 1;
  27. }
  28. 90%{
  29. -webkit-transform: rotateX(-6deg);
  30. opacity: 1;
  31. }
  32. 100%{
  33. -webkit-transform: rotateX(0deg);
  34. opacity: 1;
  35. }
  36. }
  37. @-webkit-keyframes hide {
  38. 0% {
  39. -webkit-transform: rotateX(0deg);
  40. opacity: 1;
  41. }
  42. 100%{
  43. -webkit-transform: rotateX(-180deg);
  44. opacity: 0;
  45. }
  46. }
  47. #wrap {width: 400px; height: 300px; position: relative; margin: 40px auto; -webkit-perspective: 800px; -webkit-transform-style: preserve-3d;}
  48. img {width: 400px; height: 300px; position: absolute; left: 0; top: 0; -webkit-transform-origin: bottom; -webkit-transform: rotateX(-180deg); opacity: 0;}
  49. #wrap input {width: 60px; height: 60px; margin: 0; padding: 0; background: #ccc; top: 100px; position: absolute; border-radius: 50%; outline: none; cursor: pointer;}
  50. #wrap input:nth-of-type(1) {left: -100px;}
  51. #wrap input:nth-of-type(2) {right: -100px;}
  52. .show {-webkit-transform: rotateX(0deg); opacity: 1; -webkit-animation: 1s show;}
  53. .hide {-webkit-transform: rotateX(180deg); opacity: 0; -webkit-animation: 0.6s hide;}
  54. </style>
  55. <script>
  56. window.onload = function(){
  57. var oWrap = document.getElementById('wrap');
  58. var aBtn = oWrap.getElementsByTagName('input');
  59. var aImg = oWrap.getElementsByTagName('img');
  60. var iNow = 0;
  61. aBtn[0].onclick = function(){
  62. aImg[iNow].className = 'hide';
  63. iNow--;
  64. if(iNow < 0){
  65. iNow = aImg.length - 1;
  66. }
  67. aImg[iNow].className = 'show';
  68. }
  69. aBtn[1].onclick = function(){
  70. aImg[iNow].className = 'hide';
  71. iNow++;
  72. if(iNow >= aImg.length){
  73. iNow = 0;
  74. }
  75. aImg[iNow].className = 'show';
  76. }
  77. }
  78. </script>
  79. </head>
  80. <body>
  81. <div id="wrap">
  82. <input type="button" value="上一张" />
  83. <img src="images/img1.jpg" class="show" />
  84. <img src="images/img2.jpg" />
  85. <img src="images/img3.jpg" />
  86. <img src="images/img4.jpg" />
  87. <img src="images/img5.jpg" />
  88. <input type="button" value="下一张" />
  89. </div>
  90. </body>
  91. </html>

3d折纸效果

**第一种布局方法,位置难以确定,很难实现

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>3d折纸效果</title>
  6. <style>
  7. #wrap {width: 500px; margin: 0 auto; -webkit-perspective: 800px; -webkit-transform-style: preserve-3d;}
  8. #wrap div {height: 100px; border: 1px solid #000; background: #ccc;}
  9. #wrap div:nth-of-type(1) {-webkit-transform-origin: bottom; -webkit-transform: rotateX(45deg);}
  10. #wrap div:nth-of-type(2) {-webkit-transform-origin: top; -webkit-transform: rotateX(-45deg);}
  11. #wrap div:nth-of-type(3) {-webkit-transform-origin: top; -webkit-transform: rotateX(45deg);}
  12. </style>
  13. <script>
  14. window.onload = function(){
  15. }
  16. </script>
  17. </head>
  18. <body>
  19. <div id="wrap">
  20. <div>1</div>
  21. <div>2</div>
  22. <div>3</div>
  23. </div>
  24. </body>
  25. </html>

3d折纸布局原理

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>3d折纸效果</title>
  6. <style>
  7. #wrap {width: 500px; margin: 0 auto; -webkit-perspective: 800px; -webkit-transform-style: preserve-3d; position: relative;}
  8. #wrap div {position: absolute; left: 0; top: 102px; width: 500px; -webkit-transform-origin: top; -webkit-transform-style: preserve-3d;}
  9. #wrap span {height: 100px; border: 1px solid #000; background: #ccc; display: block;}
  10. #wrap>div {top: 0;}
  11. </style>
  12. <script>
  13. window.onload = function(){
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <div id="wrap">
  19. <div style="-webkit-transform: rotateX(-45deg)">
  20. <span>1</span>
  21. <div style="-webkit-transform: rotateX(90deg)">
  22. <span>2</span>
  23. <div style="-webkit-transform: rotateX(-90deg)">
  24. <span>3</span>
  25. <div style="-webkit-transform: rotateX(90deg)">
  26. <span>4</span>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </body>
  33. </html>

3d折纸最终效果

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>3d折纸效果</title>
  6. <style>
  7. @-webkit-keyframes open {
  8. 0% {
  9. -webkit-transform: rotateX(-120deg);
  10. }
  11. 25% {
  12. -webkit-transform: rotateX(30deg);
  13. }
  14. 50% {
  15. -webkit-transform: rotateX(-15deg);
  16. }
  17. 75% {
  18. -webkit-transform: rotateX(8deg);
  19. }
  20. 100% {
  21. -webkit-transform: rotateX(0deg);
  22. }
  23. }
  24. @-webkit-keyframes close {
  25. 0% {
  26. -webkit-transform: rotateX(0deg);
  27. }
  28. 100% {
  29. -webkit-transform: rotateX(-120deg);
  30. }
  31. }
  32. body {margin: 0;}
  33. #wrap {width: 160px; margin: 30px auto;position: relative; -webkit-perspective: 800px;}
  34. #wrap h2 {height: 40px; background: #f60; color: #fff; font: bold 16px/40px "微软雅黑"; text-align: center; margin: 0; position: relative; z-index: 10;}
  35. #wrap div {position: absolute; top: 32px; width: 100%; left: 0; -webkit-transform-type: preserve-3d; -webkit-transform-origin: top; -webkit-transform: rotateX(-120deg);}
  36. #wrap span {display: block; height: 30px; background: #9f0; font: 12px/30px "宋体"; color: #fff; text-indent: 20px; box-shadow: inset 0 0 0 20px rgba(0,0,0,1); transition: 1s;}
  37. #wrap>div {top: 40px;}
  38. #wrap .show {-webkit-animation: 2s open; -webkit-transform: rotateX(0deg);}
  39. #wrap .close {-webkit-animation: 0.8s close; -webkit-transform: rotateX(-120deg);}
  40. #wrap .show>span {box-shadow: inset 0 0 0 20px rgba(0,0,0,0);;}
  41. #btn {position: absolute;}
  42. </style>
  43. <script>
  44. window.onload = function(){
  45. }
  46. </script>
  47. </head>
  48. <body>
  49. <input type="button" value="按钮" id="btn" />
  50. <div id="wrap">
  51. <h2>我是标题噢</h2>
  52. <div>
  53. <span>选项1</span>
  54. <div>
  55. <span>选项2</span>
  56. <div>
  57. <span>选项3</span>
  58. <div>
  59. <span>选项4</span>
  60. <div>
  61. <span>选项5</span>
  62. <div>
  63. <span>选项6</span>
  64. <div>
  65. <span>选项7</span>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. <script>
  75. var oBtn = document.getElementById('btn');
  76. var oWrap = document.getElementById('wrap');
  77. var aDiv = oWrap.getElementsByTagName('div');
  78. var iDelay = 200;
  79. var oTimer = null;
  80. var i = 0;
  81. var bOff = true;
  82. oBtn.onclick = function(){
  83. if(oTimer){
  84. return;
  85. }
  86. if(bOff){
  87. i = 0;
  88. oTimer = setInterval(function(){
  89. aDiv[i].className = 'show';
  90. i++;
  91. if(i == aDiv.length){
  92. clearInterval(oTimer);
  93. oTimer = null;
  94. bOff = false;
  95. }
  96. }, iDelay)
  97. } else {
  98. i = aDiv.length - 1;
  99. oTimer = setInterval(function(){
  100. aDiv[i].className = 'close';
  101. i--;
  102. if(i < 0){
  103. clearInterval(oTimer);
  104. oTimer = null;
  105. bOff = true;
  106. }
  107. }, iDelay)
  108. }
  109. }
  110. </script>
  111. </body>
  112. </html>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注