【发布时间】:2016-04-27 17:46:04
【问题描述】:
我想更改单击以打开模式框的 SVG 元素的颜色。这似乎比其他方式更困难,可能是因为我已经对 SVG 元素进行了悬停行为。
当光标在它上面时,Atm 元素是红色的并且缩放得更大,但是当我单击它以打开模式时又变回白色。如何在模态打开时将其保持为红色,并且仅在模态关闭时才变回白色?当我不点击任何东西时,我仍然想要我已经拥有的悬停行为。
asylumQ 是一个 Q 形,而 AsylumTr 是中间的一个洞。当鼠标悬停在 Q 或 Q 中的孔上时,Q 形状会变为红色(这并不完美,但使用 js 将 2 个元素组合在一起不起作用,并且在 SVG 中对它们进行分组也会破坏行为所以也许我稍后会解决这个问题)。
这里是js:
asylumQ.hover(function() {
asylumQ.attr({ opacity: 1, fill: 'red', stroke: 'red' });
asylumQ.animate({ transform: 's2,2'}, 300, mina.easein);
asylumTr.animate({ transform: 's2,2'}, 300, mina.easein);
},
function() {
asylumQ.attr({ opacity: 1, fill: 'white', stroke: 'white' });
asylumQ.animate({ transform: 's0.8,0.8'}, 300);
asylumTr.animate({ transform: 's0.8,0.8'}, 300, function () {
asylumQ.animate({ transform: 's1,1'}, 20);
asylumTr.animate({ transform: 's1,1'}, 20);
});
}
);
asylumTr.hover(function() {
asylumQ.attr({ opacity: 1, fill: 'red', stroke: 'red' });
asylumQ.animate({ transform: 's2,2'}, 300, mina.easein);
asylumTr.animate({ transform: 's2,2'}, 300, mina.easein);
},
function() {
asylumQ.attr({ opacity: 1, fill: 'white', stroke: 'white' });
asylumQ.animate({ transform: 's0.8,0.8'}, 300);
asylumTr.animate({ transform: 's0.8,0.8'}, 300, function () {
asylumQ.animate({ transform: 's1,1'}, 20);
asylumTr.animate({ transform: 's1,1'}, 20);
});
}
);
asylumTr.click(function() {
asylumQ.attr({ opacity: 1, fill: 'red', stroke: 'red' });
$('#asylumModal').modal('show');
});
【问题讨论】:
-
用你想要的颜色定义一个 CSS 类,然后在对话框打开时将它添加到元素类列表中。并在您关闭对话框时再次将其删除。
-
嗯 - 不适合我 cld 你给我看代码吗? - 我想更改不在模式中的元素的颜色。我正在尝试更改单击以打开模式的 svg 元素。
标签: javascript svg modal-dialog bootstrap-modal