zoukankan      html  css  js  c++  java
  • CSS3之transition

    随着css3不断地发展,越来越多的页面特效可以被实现。

    例如当我们鼠标悬浮在某个tab上的时候,给它以1s的渐进变化增加一个背景颜色。渐进的变化可以让css样式变化得不那么突兀,也显得交互更加柔和。

    那么怎么实现这种效果呢?
    css3提供了transition属性,可以用来控制css属性变化的速度。
    举一个盒子变化的例子,html代码如下所示。

    <body>
        <p>这是一个盒子: width, height, background-color, transform. 将光标悬停在盒子上查看动画。</p>
        <div class="box"></div>
    </body>
    
    

    css内容则如下所示。

    .box {
        border-style: solid;
        border- 1px;
        display: block;
         100px;
        height: 100px;
        background-color: yellow;
        -webkit-transition:width 2s, height 2s,
            background-color 2s, -webkit-transform 2s;
        transition:width 2s, height 2s, background-color 2s, transform 2s;
    }
    .box:hover {
        background-color: #FFCCCC;
        200px;
        height:200px;
        -webkit-transform:rotate(180deg);
        transform:rotate(180deg);
    }
    
    

    transition属性可以控制宽和高变化持续时间,如上面的css,.box的变化速度为宽和高都持续变化2秒。

    其实transition是一种简写方式,其实可以具体写各种属性和设置,例如下面是一段对文字的css变化的编写:

    #change {
        position: relative;
        transition-property: font-size;
        tansition-duration: 1s;
        transiton-delay: 1s;
        font-size: 14px;
    }
    
    #change:hover {
        tansition-property: font-size;
        transition-duration: 2s;
        tansition-=delay: 1s;
        font-size: 36px;
    }
    
    

    当然用简写是最好的,效率最高,例如:

      transition:  all 1s;
    
    
  • 相关阅读:
    李白—烂尾楼题记
    [原创]网络图片延迟加载实现,超越jquery2010年3月26日
    利用反射,泛型,扩展方法快速获取表单值到实体类
    断点续传 到底是很么
    认识LINQ
    Gridview控件用法大总结
    网站性能优化总结。
    JQ小技巧
    自己写的jq_3个小插件
    MOSS中SPuser类的使用
  • 原文地址:https://www.cnblogs.com/freephp/p/15491406.html
Copyright © 2011-2022 走看看