RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 796591
Accepted
Arthur
Arthur
Asked:2020-03-11 22:11:51 +0000 UTC2020-03-11 22:11:51 +0000 UTC 2020-03-11 22:11:51 +0000 UTC

带有 SVG 滤镜的菜单(Goo 效果)

  • 772

有一个在HTML/上实现的菜单CSS。我想出了将它与过滤器一起制作的想法,特别是每个菜单项SVG的“粘度”(Goo )效果。

1.好例子:

在此处输入图像描述

2.使用此效果制作的菜单:

在此处输入图像描述

问题:如何正确应用此菜单的过滤器?

html
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Arthur
    2020-03-11T22:11:51Z2020-03-11T22:11:51Z

    过滤器SVG是一个相当大的话题。
    使用最广泛的一种是<feGaussianBlur/>,它也出现在CSS( filter: blur(N))、<feColorMatrix/>、 <feBlend>、 <feComposite/>、 <feImage/>等 <feMerge/>中。

    在这种情况下,我们将使用<feGaussianBlur/>,<feColorMatrix/>和<feComposite/>。

    第一步:

    • 让我们从框架开始:

    $(".goo-button").on("click", function() {
      $(".goo-button").toggleClass("active");
      $(".goo-button span").toggleClass("active");
      $(".circle").toggleClass("goo-active");
    });
    * {
      margin: 0;
      padding: 0;
    }
    
    a {
      font-size: 1.5em;
      color: #fff;
    }
    
    .wrapper {
      position: relative;
      margin: 15px;
    }
    
    .goo-button {
      position: relative;
      background-color: #0066ff;
      width: 80px;
      height: 80px;
      border-radius: 50%;
      cursor: pointer;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.7);
      transition: ease-out 200ms;
    }
    
    .goo-button.active {
      transform: scale(0.8);
    }
    
    .goo-menu span {
      position: absolute;
      display: block;
      width: 40px;
      height: 4px;
      background-color: #ffffff;
      margin: 4px;
      transition: all 0.5s;
    }
    
    .goo-menu span:first-child {
      top: 26px;
      left: 15px;
    }
    
    .goo-menu span:nth-child(2) {
      top: 36px;
      left: 15px;
    }
    
    .goo-menu span:nth-child(3) {
      top: 46px;
      left: 15px;
    }
    
    .goo-menu span.active:first-child {
      top: 36px;
      transform: rotate(45deg);
    }
    
    .goo-menu span.active:nth-child(2) {
      opacity: 0;
      transition: opacity 0.3s;
    }
    
    .goo-menu span.active:nth-child(3) {
      top: 36px;
      transform: rotate(-45deg);
    }
    
    .circle {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 4em;
      height: 4em;
      background: #0066ff;
      border-radius: 50%;
      position: absolute;
      top: 8px;
      left: 8px;
      z-index: -1;
      transition: ease-out 200ms;
      cursor: pointer;
    }
    
    .c1.goo-active {
      top: 105px;
      left: 20px;
      transition-delay: 0.1s;
    }
    
    .c2.goo-active {
      top: 20px;
      left: 105px;
      transition-delay: 0.3s;
    }
    
    .c3.goo-active {
      top: 80px;
      left: 80px;
      transition-delay: 0.2s;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="wrapper">
      <div class="goo-menu">
        <div class="goo-button">
          <span></span>
          <span></span>
          <span></span>
        </div>
        <div class="circle c1"><a href="#"><i class="fa fa-pinterest"></i></a></div>
        <div class="circle c2"><a href="#"><i class="fa fa-facebook"></i></a></div>
        <div class="circle c3"><a href="#"><i class="fa fa-twitter"></i></a></div>
      </div>
    </div>

    第二步:

    • 现在我们需要使用过滤器本身,但首先是一些理论。

      SVG过滤器修改图形对象。每个过滤器元素都包含一组执行特定图形操作的过滤器原语。我们可以将操作的结果用作另一个过滤器的输入,从而为效果创建有限的范围。

    • 使用过滤器的最常见示例<feGaussianBlur/>:

    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="300" height="250">
      <defs>
        <filter id="blurEffect">
          <feGaussianBlur in="SourceGraphic" stdDeviation="5 3" />
          <!--5 - горизонтальное, 3 - вертикальное размытие -->
        </filter>
      </defs>
      <rect x="20" y="20" width="250" height="150" fill="blue" filter="url(#blurEffect)" />  
    </svg>

    -元素的过滤器HTML以这种方式连接:

    .elem{
      -webkit-filter: url("#filter");
      filter: url("#filter");
    }
    

    第三步:

    • 在我们弄清楚之后,您可以开始创建“粘性(或粘性)的效果​​。

      在最后一个代码片段中,我们使用了 3 个操作:

      1. <feGaussianBlur/>创建模糊
      2. <feColorMatrix/>增加 Alpha 通道对比度
      3. <feComposite/>内容可见性

    $(".goo-button").on("click", function() {
      $(".goo-button").toggleClass("active");
      $(".goo-button span").toggleClass("active");
      $(".circle").toggleClass("goo-active");
    });
    * {
      margin: 0;
      padding: 0;
    }
    
    a {
      font-size: 1.5em;
      color: #fff;
    }
    
    .wrapper {
      position: relative;
      margin: 15px;
    }
    
    
    /*Подключаем наши фильтры*/
    
    .goo-menu {
      -webkit-filter: url(#gooEffect");
      filter: url("#gooEffect");
    }
    
    .goo-button {
      position: relative;
      background-color: #0066ff;
      width: 80px;
      height: 80px;
      border-radius: 50%;
      cursor: pointer;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.7);
    }
    
    .goo-button.active {
      transform: scale(0.8);
    }
    
    .goo-menu span {
      position: absolute;
      display: block;
      width: 40px;
      height: 4px;
      background-color: #ffffff;
      margin: 4px;
      transition: all 400ms;
    }
    
    .goo-menu span:first-child {
      top: 26px;
      left: 15px;
    }
    
    .goo-menu span:nth-child(2) {
      top: 36px;
      left: 15px;
    }
    
    .goo-menu span:nth-child(3) {
      top: 46px;
      left: 15px;
    }
    
    .goo-menu span.active:first-child {
      top: 36px;
      transform: rotate(45deg);
    }
    
    .goo-menu span.active:nth-child(2) {
      opacity: 0;
      transition: opacity 300ms;
    }
    
    .goo-menu span.active:nth-child(3) {
      top: 36px;
      transform: rotate(-45deg);
    }
    
    .circle {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 4em;
      height: 4em;
      background: #0066ff;
      border-radius: 50%;
      position: absolute;
      top: 8px;
      left: 8px;
      z-index: -1;
      transition: ease-out 200ms;
      cursor: pointer;
    }
    
    .c1.goo-active {
      top: 105px;
      left: 20px;
      transition-delay: 100ms;
    }
    
    .c2.goo-active {
      top: 20px;
      left: 105px;
      transition-delay: 300ms;
    }
    
    .c3.goo-active {
      top: 80px;
      left: 80px;
      transition-delay: 200ms;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="wrapper">
      <div class="goo-menu">
        <div class="goo-button">
          <span></span>
          <span></span>
          <span></span>
        </div>
        <div class="circle c1"><a href="#"><i class="fa fa-pinterest"></i></a></div>
        <div class="circle c2"><a href="#"><i class="fa fa-facebook"></i></a></div>
        <div class="circle c3"><a href="#"><i class="fa fa-twitter"></i></a></div>
      </div>
    </div>
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/2000/svg" version="1.1">
      <defs>
        <filter id="gooEffect">
          <feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />
          <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 18 -7" result="goo" />
          <feComposite in="SourceGraphic" result="mix"/>
        </filter>
      </defs>
    </svg>

    PS不要在大面积上使用这些过滤器,因为它们非常耗费资源。

    • 14

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5