• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

CSS的动态展开效果

武飞扬头像
惊梦散人
帮助5

大家经常看到一些把鼠标移到图标上,然后图标动态变换成新的图标的效果,这里就是用到HTML(CSS)的<scan>功能。

这里给大家一个示例:

css:

  1.  
    .share-button{
  2.  
    width: 100px;
  3.  
    height: 40px;
  4.  
    background-color: #fff;
  5.  
    border-radius: 20px;
  6.  
    display: flex;
  7.  
    justify-content: center;
  8.  
    align-items: center;
  9.  
    position: relative;
  10.  
    cursor: pointer;
  11.  
    /* 溢出隐藏 */
  12.  
    overflow: hidden;
  13.  
    /* 加个动画过渡 */
  14.  
    transition: 0.3s linear;
  15.  
    }
  16.  
    .share-button:hover{
  17.  
    /* 放大1.1倍 */
  18.  
    transform: scale(1.1);
  19.  
    }
  20.  
    .share-button span{
  21.  
    position: absolute;
  22.  
    width: 100%;
  23.  
    height: 100%;
  24.  
    background-color: #333;
  25.  
    color: #fff;
  26.  
    font-size: 15px;
  27.  
    text-align: center;
  28.  
    line-height: 40px;
  29.  
    border-radius: 20px;
  30.  
    z-index: 1;
  31.  
    /* 动画过渡 */
  32.  
    transition: 0.6s linear;
  33.  
    }
  34.  
    .share-button:hover span{
  35.  
    /* 沿X轴移动 */
  36.  
    transform: translateX(-100%);
  37.  
    /* 动画延迟 */
  38.  
    transition-delay: 0.3s;
  39.  
    }
  40.  
    .share-button a{
  41.  
    flex: 1;
  42.  
    font-size: 10px;
  43.  
    color: #333;
  44.  
    text-align: center;
  45.  
    transform: translateX(-100%);
  46.  
    /* 不透明度 */
  47.  
    opacity: 0;
  48.  
    transition: 0.3s linear;
  49.  
    }
  50.  
    .share-button:hover a{
  51.  
    opacity: 1;
  52.  
    transform: translateX(0);
  53.  
    }
  54.  
    /* 接下来为每一个a元素(图标)分别设置动画延迟 */
  55.  
    /* :nth-of-type(n)选择器是匹配属于父元素的特定类型的第n个子元素的每个元素 */
  56.  
    .share-button a:nth-of-type(1){
  57.  
    transition-delay: 1s;
  58.  
    }
  59.  
    .share-button a:nth-of-type(2){
  60.  
    transition-delay: 0.8s;
  61.  
    }
  62.  
    .share-button a:nth-of-type(3){
  63.  
    transition-delay: 0.6s;
  64.  
    }
  65.  
    .share-button a:nth-of-type(4){
  66.  
    transition-delay: 0.4s;
  67.  
    }
学新通

HTML:

  1.  
    <link rel="stylesheet" href="22.css">
  2.  
    <meta charset="UTF-8">
  3.  
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  4.  
    <div class="share-button" controls>
  5.  
    <span><i class="fa fa-share-alt" aria-hidden="true"></i> Kevin</span>
  6.  
    <a href="#"><i class="fa fa-mail-forward" aria-hidden="true"></i></a>
  7.  
    <a href="#"><i class="fa fa-music" aria-hidden="true"></i></a>
  8.  
    <a href="#"><i class="fa fa-ban" aria-hidden="true"></i></a>
  9.  
    </div>

上面这串代码没有加head等东东,大家只要将这个随意放在<head>或者<body>中都是可以的。

另外,这里用到了fa fa图标,给大家分享一下fa fa 库

http://www.fontawesome.com.cn/faicons/

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhffjgea
系列文章
更多 icon
同类精品
更多 icon
继续加载