[英]Make svg polygon button with text change color on mouseover?
<svg viewbox='0 0 80 80'>
<polygon id=button points='50,0 80,80 0,80'/>
<text x=40 y=50>HELLO</text>
</svg>
我有一个带有文本的多边形按钮,当你将鼠标悬停在它上面时,我希望多边形更亮。 问题是当您将鼠标悬停在文本上时,多边形会变回黑暗。
我更喜欢使用html / css,但只要我不需要另一个库,我就可以使用javascript / jquery。
我希望能够做到以下其中一项来解决它:
我觉得这很简单......我遇到了一些恼人的限制。
您可以使用<g>
嵌套svg
元素:
<svg viewbox='0 0 80 80'>
<g id=button>
<polygon points='50,0 80,80 0,80'/>
<text x=40 y=50>HELLO</text>
</g>
</svg>
然后应用CSS样式:
#button {
cursor: pointer;
fill: #900;
}
#button:hover {
cursor: pointer;
fill: #F00;
}
text {
font-size:7px;
fill: black;
}
请参阅: http : //jsfiddle.net/J7psN/1/
您可以使用:
$( "#button" ).hover(
function() {
$(this).css('fill' ,'#F00');
}, function() {
$(this).css('fill' ,'#900');
}
);
$('text').mouseover(function(e) {
$(this).prev().mouseover();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.