HTML5基础加强css样式篇(css过度效果)(十八)
2017-03-16 11:02
585 查看
1.css过度效果简介:
3.过度时间设置transition-duration
css过度效果:动态边框应用:
效果图:
代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> .box { width: 100px; height: 100px; background-color: #7e64ff; /*visibility: hidden;*/ } /*鼠标悬浮在.box时,宽度放大2倍*/ .box:hover{ /*设置有过渡效果的CSS属性*/ /* 对CSS属性的要求:具有“中间值”得CSS样式 中间值: CSS样式是数值或者可以转化成数值 */ /*transition-property: width;*/ /*transition-property: opacity;*/ /*transition-property: display;*/ /*transition-property: visibility;*/ transition-property: background-color; /*#f00 = red*/ background-color: red; /*opacity: 1;*/ /*display: block;*/ /*设置过渡持续的时间*/ transition-duration: 3s; /*width: 200px;*/ /*opacity: 0;*/ /*display: none;*/ /*visibility: hidden;*/ } </style> </head> <body> <div class="box"> </div> <script type="text/javascript"> </script> </body> </html>2.css过度效果简单应用:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> .box { width: 100px; height: 100px; background-color: #7e64ff; border: 1px solid green; } /*需求:鼠标悬浮在.box时,宽度放大2倍,背景色变成红色,高度放大2倍*/ .box:hover{ /*通过,分割多个样式*/ /* 我们不需要特别设置 transition-property: 浏览器默认为我们增加了 transition-property: all */ /*transition-property: width, background-color, height, border;*/ /*transition-property: all;*/ /*仅让宽度产生过渡动画效果*/ transition-property: width; /*当特指某个CSS样式具有过渡动画效果,需要显示设置 transition-property*/ transition-duration: 3s; width: 200px; height: 200px; background-color: #f00; border: 19px solid green; } </style> </head> <body> <div class="box"> </div> <script type="text/javascript"> </script> </body> </html>
3.过度时间设置transition-duration
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>过度时间设置</title> <style type="text/css"> .box { width: 100px; height: 100px; background-color: #7e64ff; border: 1px solid green; } .box:hover{ /*仅让宽度产生过渡动画效果,过渡时间3ms, 高度4s, 背景色过渡*/ transition-property: width, height, background-color, border; /*transition-duration: 3s;*/ /*transition-duration: 300ms;*/ transition-duration: 2s, 4s, 10s; /* 过渡时间值 ms 毫秒 s 秒 */ width: 200px; height: 200px; background-color: #f00; border: 19px solid green; } </style> </head> <body> <div class="box"> </div> <script type="text/javascript"> </script> </body> </html>4.过度延时时间:transition-delay
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> .box, .box1 { width: 100px; height: 100px; background-color: #7e64ff; border: 1px solid green; } body:hover .box{ /*transition-property: width, height, background-color, border;;*/ transition-property: width; transition-duration: 2s; /*过渡延迟执行*/ /*transition-delay: 1s, .1s;*/ /*可以设置负值*/ transition-delay: -1s; width: 200px; /*height: 200px;*/ /*background-color: #f00;*/ /*border: 19px solid green;*/ } body:hover .box1{ transition-property: width; transition-duration: 2s; width: 200px; } </style> </head> <body> <div class="box"></div> <div class="box1"></div> <script type="text/javascript"> </script> </body> </html>
css过度效果:动态边框应用:
效果图:
代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> .box { width: 400px; height: 150px; background-color: forestgreen; position: relative; } .border-box{ background-color: orange; position: absolute; } .border-box-top{ height: 8px; width: 0; } .border-box-right{ width: 8px; height: 0; right: 0; } .border-box-bottom{ height: 8px; width: 0; bottom: 0; right: 0; } .border-box-left{ width: 8px; height: 0; left: 0; bottom: 0; } /* 触发时机:鼠标悬浮在 .box 过渡时间:每个边的过渡时间是1s CSS值变化: 0 到指定的大小 */ .box:hover .border-box-top{ width: 100%; transition-duration: 1s; } .box:hover .border-box-right{ height: 100%; transition-duration: 1s; transition-delay: 1s; } .box:hover .border-box-bottom{ width: 100%; transition-duration: 1s; transition-delay: 2s; } .box:hover .border-box-left{ height: 100%; transition-duration: 1s; transition-delay: 3s; } </style> </head> <body> <div class="box"> <div class="border-box border-box-top"></div> <div class="border-box border-box-right"></div> <div class="border-box border-box-bottom"></div> <div class="border-box border-box-left"></div> </div> <script type="text/javascript"> </script> </body> </html>
相关文章推荐
- HTML5基础加强css样式篇(css过度效果:界面的浮层遮罩和消失)(十九)
- HTML5基础加强css样式篇(css过度覆盖问题)(二十一)
- HTML5基础加强css样式篇(css过渡属性简写,cubic-bezier过度曲线函数使用)(二十)
- HTML5基础加强css样式篇(css属性border圆角:border-radius)(三十五)
- HTML5基础加强css样式篇(文字阴影css属性:text-shadow)(四十四)
- HTML5基础加强css样式篇(css属性transform 函数(3D)transform-style)(二十五)
- HTML5基础加强css样式篇(css属性transform 函数(2D)的scale(),transform-origin,skew(),translate(),rotate() )(二十四)
- HTML5基础加强css样式篇(css属性transform 函数(2D)时钟)(二十六)
- HTML5基础加强css样式篇(css过渡属性的隐式过渡问题)(二十二)
- HTML5基础加强css样式篇(css属性transform 函数(3D)3D盒子)(二十七)
- HTML5基础加强css样式篇(css属性border详解(一))(三十三)
- HTML5基础加强css样式篇(css过渡结束事件:transitionend)(二十三)
- HTML5基础加强css样式篇(css属性:怪异盒模型解析)(四十六)
- HTML5基础加强css样式篇(css属性border详解:图片边框border-image-slice,border-image-repeat,border-image-width(二))(三十四)
- HTML5基础加强css样式篇(css计算函数:calc())(四十七)
- HTML5基础加强css样式篇(伪元素first-letter,first-line,selection和css计数函数counter,counters)(十六)
- HTML5基础加强css样式篇(font-family,font-size, font-style,font-variant, font-weight , font 简写属性 )(五)
- HTML5基础加强css样式篇(多媒体选择器)(十七)
- HTML5基础加强css样式篇(animation简写,控制多个动画,动画帧简写)(三十二)
- HTML5基础加强css样式篇(target目标伪类选择器)(九)