首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何动画svg filter feComponentTransfer?

如何动画svg filter feComponentTransfer?
EN

Stack Overflow用户
提问于 2019-04-15 20:30:19
回答 1查看 229关注 0票数 2

有人知道如何在feComponentTransfer的feFuncRGB中使用动画标签吗?我有一个SVG过滤器,我需要在点击时显示/隐藏它,并进行一些转换。

大概是这样的:

代码语言:javascript
复制
<svg xmlns="http://www.w3.org/2000/svg" id="svg-filters">
    <filter id="duotone">
        <feComponentTransfer color-interpolation-filters="sRGB" result="duotone_cyan_blue">
            <feFuncR type="table" tableValues="0.2489 0.9589">
                <animate 
                id="animate"
                attributeName="tableValues" 
                dur="2s" 
                from="0 1" 
                to="0.2489 0.9589" 
                fill="freeze" 
                />
            </feFuncR>
        </feComponentTransfer>
    </filter>
</svg>

对于feFuncG和feFuncB也是如此

代码语言:javascript
复制
$('img').click( function() {
  $("#animate").beginElement();
});

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-15 21:19:50

一种解决方案是使用如下svg图像:

代码语言:javascript
复制
svg.addEventListener("click",() =>{
  _animate.beginElement();
})
代码语言:javascript
复制
<svg xmlns="http://www.w3.org/2000/svg" id="svg" width="300" height="300" >
    <filter id="duotone">
        <feComponentTransfer color-interpolation-filters="sRGB" result="duotone_cyan_blue">
            <feFuncR type="table" tableValues="0 1">
               <animate 
                id="_animate"
                attributeName="tableValues" 
                dur="2s" 
                values="0 1;1 0" 
                fill="freeze"
                begin="svg.click"
                />
            </feFuncR>
        </feComponentTransfer>
    </filter>
  
  <image xlink:href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/darwin300.jpg" width="300" height="300" filter="url(#duotone)"></image>
</svg>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55689244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档