Javascript SVG图标仅变形一次,赢得';t变形回
我使用基于用户点击前后变形两个图标。我有两个问题 1) 第一个图标最初不显示。我意识到这是因为 我在那里放了一个Javascript SVG图标仅变形一次,赢得';t变形回,javascript,jquery,css,svg,Javascript,Jquery,Css,Svg,我使用基于用户点击前后变形两个图标。我有两个问题 1) 第一个图标最初不显示。我意识到这是因为 我在那里放了一个显示:none,但在 演示。我是否应该取消初始图标的显示:无样式 2) 当我第一次点击“联系”文本时,图标会变形 好的但是,当我再次单击文本(现在是“项目”)时,图标 不会变形回来 我为工作图标创建了两个函数,使其变形为邮件图标,反之亦然。另外,如果有更有效的方法将这两个函数合并为一个函数,我洗耳恭听 我哪里出错了 小提琴: HTML <div id="icons">
显示:none
,但在
演示。我是否应该取消初始图标的显示:无
样式
2) 当我第一次点击“联系”文本时,图标会变形
好的但是,当我再次单击文本(现在是“项目”)时,图标
不会变形回来
我为工作图标创建了两个函数,使其变形为邮件图标,反之亦然。另外,如果有更有效的方法将这两个函数合并为一个函数,我洗耳恭听
我哪里出错了
小提琴:
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>
我明白了。我想我只能使用
var-myIcons=new-SVGMorpheus(“#iconset”)代码>一次。这是最终结果:使您的第一个图标显示:block代码>。不要一次单击就调用这两个函数,而是使它们不同单击函数
function morphWork() {
var myIcons = new SVGMorpheus('#iconset');
myIcons.to('mail');
};
function morphMail() {
var myIcons = new SVGMorpheus('#iconset');
myIcons.to('work');
};
要获得邮件图标,您必须更改邮件功能
function morphWork() {
var myIcons = new SVGMorpheus('#iconset');
myIcons.to('mail');
};
function morphMail() {
var myIcons = new SVGMorpheus('#iconset');
myIcons.to('work');
};
对此
function morphWork() {
var myIcons = new SVGMorpheus('#iconset');
myIcons.to('work');
};
function morphMail() {
var myIcons = new SVGMorpheus('#iconset');
myIcons.to('mail');
};