RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1027897
Accepted
Andrew Gor
Andrew Gor
Asked:2020-09-25 18:53:59 +0000 UTC2020-09-25 18:53:59 +0000 UTC 2020-09-25 18:53:59 +0000 UTC

根据 SVG 下的图像颜色自动更改 SVG 颜色

  • 772

在svg中有一个徽标。

我需要根据徽标下的主色将徽标的颜色更改为白色或黑色。

我试图为此目的使用插件BackgroundCheck。在一个干净的html插件中,它可以工作,但是当我加载它时Тильду,它就不起作用了。

在我看来,我的风格被忽视了。我究竟做错了什么?

<!--logo-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<html>

<head>
  <style type="text/css" media="screen">
    .images {
      width: 100%;
      display: block;
    }
    
    .fixed-nav {
      /* 	background-color: red; */
      position: fixed;
      left: 100px;
      top: 47px;
      width: 80px;
      z-index: 99999;
    }
    
    .fixed-nav.background--dark .fixed-nav-line {
      /*   background: #fff; */
    }
    
    .fixed-nav.background--dark .fixed-nav-logo {
      background-image: url(https://static.tildacdn.com/tild3831-3566-4637-b934-383138346332/Awhite.svg);
      height: 43px;
      width: 33px;
      /* 		fill: white; */
      /*   color: #fff; */
    }
    
    .fixed-nav.background--light .fixed-nav-logo {
      background-image: url(https://static.tildacdn.com/tild6133-3534-4237-b863-666531326632/A.svg);
      height: 43px;
      width: 33px;
    }
    
    .fixed-nav-line,
    .fixed-nav-logo {
      background-image: url(https://static.tildacdn.com/tild6133-3534-4237-b863-666531326632/A.svg);
      display: inline-block;
      vertical-align: middle;
      margin: 0;
      padding: 0;
    }
    
    .fixed-nav-line {
      width: 40px;
      height: 3px;
      background: #222;
    }
    
    .fixed-nav-logo {
      /* 	background-color: yellow; */
      width: 33px;
      height: 43px;
      font-size: 28px;
      font-weight: bold;
      text-align: center;
      z-index: 99999;
    }
  </style>
  <script src="https://hosting.maass.ua/background-check.min.js"></script>
  <script src="https://hosting.maass.ua/fixed-nav.js"></script>
</head>

<body>
  <!--<div class="fixed">-->
  <div class="fixed-nav">
    <a href="#">
      <div class="fixed-nav-logo"></div>
    </a>
  </div>
  <!--</div> -->
  <div class="images">
    <img class="images" src="https://static.tildacdn.com/tild6361-3535-4136-a662-353763663866/12049949b04d4882bcdf.jpg" />
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <img class="images" src="https://static.tildacdn.com/tild3837-6362-4139-b933-616635623530/maass-RO-hall-30.jpg" />
  </div>
</body>

</html>

PS也许还有其他方法可以解决我的问题?

提前致谢。

javascript
  • 4 4 个回答
  • 10 Views

4 个回答

  • Voted
  1. Best Answer
    Stranger in the Q
    2020-09-25T19:18:21Z2020-09-25T19:18:21Z

    试试这样:

      mix-blend-mode: difference;
      filter: invert(.7);
    

    .images {
      width: 100%;
      display: block;
    }
    
    .fixed-nav {
      position: fixed;
      left: 100px;
      top: 47px;
      mix-blend-mode: difference;
      filter: invert(.7);
    }
    
    .fixed-nav-logo {
      width: 150px;
      height: 200px;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='150px' height='200px' viewBox='0 0 33 44'%3E%3C!-- Generator: Sketch 55.2 (78181) - https://sketchapp.com --%3E%3Ctitle%3EGroup 6%3C/title%3E%3Cdesc%3ECreated with Sketch.%3C/desc%3E%3Cdefs%3E%3Cpolygon id='path-1' points='0.0003 0.2282 32.824 0.2282 32.824 29 0.0003 29'/%3E%3C/defs%3E%3Cg id='Page-1' stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'%3E%3Cg id='iPhone-8-Copy-3' transform='translate(-273.000000, -27.000000)'%3E%3Cg id='Group-6' transform='translate(273.000000, 29.000000)'%3E%3Cg id='Group-3' transform='translate(0.000000, 12.292900)'%3E%3Cmask id='mask-2' fill='white'%3E%3Cuse xlink:href='%23path-1'/%3E%3C/mask%3E%3Cg id='Clip-2'/%3E%3Cpath d='M20.7453,18.2922 L18.9043,13.3612 C18.0503,11.2202 17.1073,8.5922 16.2093,6.0882 C15.3113,8.5922 14.3693,11.2202 13.5613,13.3612 L11.7193,18.2922 L20.7453,18.2922 Z M22.9003,23.9892 L9.6093,23.9892 L7.7683,29.0002 L0.0003,29.0002 L11.7643,0.2282 L20.7903,0.2282 L32.8243,29.0002 L24.7863,29.0002 L22.9003,23.9892 Z' id='Fill-1' fill='%231D1D1B' mask='url(%23mask-2)'/%3E%3C/g%3E%3Cpath d='M23.1925,7.7951 C23.1925,11.6391 20.0765,14.7551 16.2325,14.7551 C12.3875,14.7551 9.2715,11.6391 9.2715,7.7951 C9.2715,3.9511 12.3875,0.8341 16.2325,0.8341 C20.0765,0.8341 23.1925,3.9511 23.1925,7.7951 Z' id='Stroke-4' stroke='%231D1D1B' stroke-width='5.669'/%3E%3C/g%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    }
    <div class="fixed-nav">
      <a href="#">
        <div class="fixed-nav-logo"></div>
      </a>
    </div>
    <div class="images">
      <img class="images" src="https://picsum.photos/id/1/600/600" />
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      <br/>
      <img class="images" src="https://picsum.photos/id/2/600/600" />
    </div>

    • 12
  2. Игорь
    2020-09-26T14:40:22Z2020-09-26T14:40:22Z

    我最近遇到了类似的问题。我发现的唯一且非常有争议的实现选项需要连接tweenmax并复制徽标(在您的情况下)。另一个缺点 - 滚动时,不时会观察到抽搐​​。但是,我没有找到替代方案。

    function logoSwitch () {
      $('.icon-container.abso').each(function() {
        
        var distance = $('.icon-container').offset().top - $(this).closest('.row').offset().top;
        
        TweenLite.to(this,0,{y:distance, force3D:true});
      });
    };
    
    $(document).scroll(function() {
      logoSwitch();
    });
    
    logoSwitch();
    * {
      padding: 0;
      margin: 0;
    }
    
    body {
      font-family: 'Playfair Display', serif;
    }
    
    .row {
      min-height: 110vh;
      overflow: hidden;
      position: relative;
      width: 100%;
    }
    
    .icon-container {
      display: flex;
      flex-direction: column;
      position: fixed;
      top: 20px;
      left: 20px;
      transform: translate3d(0, 0, 0);
      -webkit-transform-style: preserve-3d;
    }
    .icon-container.abso {
      position: absolute;
      top: 0;
      left: 20px;
    }
    .icon-container .logo {
      width: 300px;
    }
    
    .logo {
      width: 300px;
      cursor: pointer;
    }
    
    .startLogo:active {
      animation: repaint 1ms;
    }
    
    .whiteLogo {
      fill: white;
      stroke: white;
    }
    
    .blackLogo {
      color: #1d1d1d;
    }
    
    .grey {
      background: #ccc;
    }
    
    .blue {
      background: skyBlue;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script>
    
    <div class="row grey ">
      <div class="icon-container">
          <svg class="logo blackLogo startLogo repaint animate" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 734.61 235.64">
        <path d="M527.21 151.39s21.37 20.83 28.13 28.12c15.17 16.38 73.92 52.5 130.7 0 0 0 27.07-23.11 27.07-65.3 0-32.7-15.34-53.58-27.06-65.3-13.28-13.28-69.66-54.4-130.71 0L425.05 179.53c-61.05 54.39-117.43 13.27-130.71 0-11.72-11.72-27.06-32.6-27.06-65.3 0-42.19 27.07-65.3 27.07-65.3 56.77-52.5 115.53-16.38 130.7 0 6.76 7.29 28.13 28.12 28.13 28.12" fill="none" stroke="#181818" stroke-miterlimit="10" stroke-width="43" class="OO"/>
        <g id="R">
        <g id="R-2" data-name="R">
          <path class="cls-2" d="M247.46 335.39c-27.75 27.73-71.52 27-99.27-.72-6.87-6-41.49-38.56-41.49-38.56C73.79 265 55.89 256.38 25 256.38v42.94c22.44 0 33.21 8.68 67.63 41.82 5.62 5.41 22.8 20.93 26 23.69 44.44 44.4 114.59 45.15 159 .75z" transform="translate(-25 -162.87)"/>
          <path class="cls-2" d="M151.72 213.2c27.2 0 50.33 21.79 50.33 48.44 0 15.12-7.46 28.67-18.88 37.57l30.46 30.44a90.09 90.09 0 0 0 31.14-68c0-50.31-41.62-91.09-93-91.13H25v42.68z" transform="translate(-25 -162.87)"/>
        </g>
        </g>
        </svg>
      </div>
    </div>
    
    <div class="row blue">
      <div class="icon-container abso">
        <svg class="logo whiteLogo altLogo animate " xmlns="http://www.w3.org/2000/svg" viewBox="0 0 734.61 235.64">
    
        <path d="M527.21 151.39s21.37 20.83 28.13 28.12c15.17 16.38 73.92 52.5 130.7 0 0 0 27.07-23.11 27.07-65.3 0-32.7-15.34-53.58-27.06-65.3-13.28-13.28-69.66-54.4-130.71 0L425.05 179.53c-61.05 54.39-117.43 13.27-130.71 0-11.72-11.72-27.06-32.6-27.06-65.3 0-42.19 27.07-65.3 27.07-65.3 56.77-52.5 115.53-16.38 130.7 0 6.76 7.29 28.13 28.12 28.13 28.12" fill="none"  stroke-miterlimit="10" stroke-width="43" class="OO"/>
        <g id="R">
        <g id="R-2" data-name="R">
          <path class="cls-2" d="M247.46 335.39c-27.75 27.73-71.52 27-99.27-.72-6.87-6-41.49-38.56-41.49-38.56C73.79 265 55.89 256.38 25 256.38v42.94c22.44 0 33.21 8.68 67.63 41.82 5.62 5.41 22.8 20.93 26 23.69 44.44 44.4 114.59 45.15 159 .75z" transform="translate(-25 -162.87)"/>
          <path class="cls-2" d="M151.72 213.2c27.2 0 50.33 21.79 50.33 48.44 0 15.12-7.46 28.67-18.88 37.57l30.46 30.44a90.09 90.09 0 0 0 31.14-68c0-50.31-41.62-91.09-93-91.13H25v42.68z" transform="translate(-25 -162.87)"/>
        </g>
        </g>
        </svg>
      </div>
    </div>

    • 7
  3. xmoonlight
    2020-10-09T03:38:03Z2020-10-09T03:38:03Z

    完成 - 见这里: https ://jsfiddle.net/xmoonlight/zatdu0v2/

    这是代码的主要部分:

    function setLogoColor(eImg,eSVGLogo,bw) {
        var c=getAverageRGB(eImg,eSVGLogo);
      if(bw) {
        eSVGLogo.style.fill=(c.l<128)?'rgb(255,255,255)':'rgb(0,0,0)';
    
        } else eSVGLogo.style.fill='rgb('+c.r+','+c.g+','+c.b+')';  
    }
    
    setLogoColor(document.querySelector('.img img'),document.querySelector('.img svg'),1);
    
    • 0
  4. xmoonlight
    2020-10-10T11:58:25Z2020-10-10T11:58:25Z

    通过 CSS3 过滤器,如果您使用过滤器链,您可以获得可接受的结果。

    将 SVG 徽标的颜色设置为黑色。如果是白色,则将 invert() 过滤器从 1 更改为 0。brightness() 过滤
    器有助于减少徽标后面图像中具有强烈色差的颜色过渡波(60% 为 +/-10%) .
    过滤器的顺序和样式的顺序非常重要!

    演示:https ://jsfiddle.net/xmoonlight/7wgnxfsd/

    <style>
    .img svg { /* SVG LOGO: style="fill:#000000" */
      position: absolute;
      filter: invert(1) sepia(100%) brightness(60%) saturate(0);
      mix-blend-mode: exclusion;
      right: 30px;
      bottom: 30px;
    }
    </style>
    
    • 0

相关问题

Sidebar

Stats

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

    根据浏览器窗口的大小调整背景图案的大小

    • 2 个回答
  • Marko Smith

    理解for循环的执行逻辑

    • 1 个回答
  • Marko Smith

    复制动态数组时出错(C++)

    • 1 个回答
  • Marko Smith

    Or and If,elif,else 构造[重复]

    • 1 个回答
  • Marko Smith

    如何构建支持 x64 的 APK

    • 1 个回答
  • Marko Smith

    如何使按钮的输入宽度?

    • 2 个回答
  • Marko Smith

    如何显示对象变量的名称?

    • 3 个回答
  • Marko Smith

    如何循环一个函数?

    • 1 个回答
  • Marko Smith

    LOWORD 宏有什么作用?

    • 2 个回答
  • Marko Smith

    从字符串的开头删除直到并包括一个字符

    • 2 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +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