gpt4 book ai didi

javascript - Greensock 动画不适用于 SVG 高度

转载 作者:行者123 更新时间:2023-12-04 20:15:09 26 4
gpt4 key购买 nike

我只是想做一个非常简单的 tweenMax 动画,其中条的高度从 “0”“100%”。现在我的 SVG 如下所示:

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 69 64" style="enable-background:new 0 0 69 64;" xml:space="preserve">
<style type="text/css">
.st0{fill:#712215;}
.st1{fill:none;stroke:#712215;stroke-miterlimit:10;}
</style>
<path id="XMLID_8_" class="st0" d="M23,47.4h-5.4c-0.6,0-1-0.5-1-1v-6.9c0-0.5,0.4-1,1-1H23c0.5,0,1,0.5,1,1v6.9
C24,47,23.5,47.4,23,47.4z"/>
<path id="XMLID_7_" class="st0" d="M31.9,47.4h-5.4c-0.5,0-1-0.5-1-1V32.9c0-0.5,0.5-1,1-1h5.4c0.6,0,1,0.5,1,1v13.5
C32.9,47,32.5,47.4,31.9,47.4z"/>
<path id="XMLID_6_" class="st0" d="M41.9,47.4h-5.4c-0.6,0-1-0.5-1-1V36c0-0.5,0.4-1,1-1h5.4c0.5,0,1,0.5,1,1v10.5
C42.9,47,42.5,47.4,41.9,47.4z"/>
<path id="XMLID_5_" class="st0" d="M51,47.4h-5.4c-0.5,0-1-0.5-1-1V30c0-0.5,0.5-1,1-1H51c0.6,0,1,0.5,1,1v16.4
C52,47,51.5,47.4,51,47.4z"/>
<polygon id="XMLID_4_" class="st0" points="16.6,35 18,36.4 29.6,25.6 38.9,33 49.3,21.9 47.3,20 38.9,29.5 29.2,21.8 15.9,34.5 "/>
<polygon id="XMLID_3_" class="st0" points="43.2,17.8 51.7,17.9 51.9,26 "/>
<rect id="XMLID_2_" x="2.5" y="11.6" class="st1" width="63.5" height="40.8"/>
</svg>

Fiddle here .现在我有以下 JavaScript 来为条形图设置动画:

$(function () {   
var tx = new TimelineMax();
TweenMax.fromTo($('path')[0] , 2 , { css : { height : 0 } } , { css : { height : '100px' } });
});

但高度动画似乎不起作用。我做错了什么?

最佳答案

问题是 height 不是路径元素支持的属性;

一个简单的解决方法是使用 transform:scaleY :

  TweenMax.fromTo($('path')[0], 2, {
css: {
transform: 'scaleY(0)'
// height: 0
}
}, {
css: {
transform: 'scaleY(1)'
//height: '100px'
}
});

fiddle

对于更个性化的解决方案,您可能会考虑更改 d 属性...

关于javascript - Greensock 动画不适用于 SVG 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36827171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com