gpt4 book ai didi

javascript - SVG 图标只变形一次,不会变形回来

转载 作者:行者123 更新时间:2023-11-28 08:39:07 25 4
gpt4 key购买 nike

我正在使用 SVG Morpheus根据用户点击来回变形两个图标。我有两个问题。

1) The first icon initially doesn't show up. I realize this is because I put a display:none on there but that's how it was shown in the demo. Am I supposed to take off the display:none styling for the initial icon?

2) When I first click on the 'Get in Touch' text, the icon morphs fine. However, when I click the text (now 'Projects') again, the icon doesn't morph back.

我已经为工作图标创建了两个函数来变身为邮件图标,反之亦然。此外,如果有更有效的方法将这两个功能合并为一个功能,我会洗耳恭听。

我哪里做错了?

fiddle :http://jsfiddle.net/o8u9225q/5/

HTML

<div id="icons">
<svg id="iconset" height="24" width="24" viewbox="0 0 24 24">
<g id="work" style="display:none">
<rect width="6.5" height="6.5"/>
<rect x="8.7" width="6.5" height="6.5"/>
<rect x="17.5" width="6.5" height="6.5"/>
<rect y="8.7" width="6.5" height="6.5"/>
<rect x="8.7" y="8.7" width="6.5" height="6.5"/>
<rect x="17.5" y="8.7" width="6.5" height="6.5"/>
<rect y="17.5" width="6.5" height="6.5"/>
<rect x="8.7" y="17.5" width="6.5" height="6.5"/>
<rect x="17.5" y="17.5" width="6.5" height="6.5"/>
</g>
<g id="mail" style="display:none">
<polygon points="1.1,3.2 6.6,3.2 12.5,3.2 12,12.5"/>
<polygon points="8.7,3.2 15.3,3.2 15.3,9.6 12,12.5"/>
<polygon points="20.5,3.2 23,3.2 12,12.5 13.1,3.2"/>
<polygon points="0,4.2 6.5,14.5 6.5,20.9 0,20.9"/>
<rect x="8.7" y="14.5" width="6.5" height="6.4"/>
<rect x="17.5" y="14.5" width="6.5" height="6.4"/>
<polygon points="0,4.2 12,14.5 6.5,20.9 0,20.9"/>
<rect x="6.3" y="14.5" width="11.4" height="6.4"/>
<polygon points="12,14.5 24,4.2 24,20.9 17.5,20.9"/>
</g>
</svg>
</div>
<a id="contact-button" href="#">Get in touch</a>

JS

var c = 0;

function morphWork() {
var myIcons = new SVGMorpheus('#iconset');
myIcons.to('mail');
};

function morphMail() {
var myIcons = new SVGMorpheus('#iconset');
myIcons.to('work');
};

$('#contact-button').click(function (e) {
e.preventDefault();

if (c++ % 2 == 0) {

$(this).addClass('project-button').text('Projects');
morphMail();

} else {

$(this).removeClass('project-button').text('Get in touch');
morphWork();
}
});

最佳答案

想通了。我猜我只能使用 var myIcons = new SVGMorpheus('#iconset'); 一次。这是最终结果:http://jsfiddle.net/o8u9225q/6/

关于javascript - SVG 图标只变形一次,不会变形回来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27899177/

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