[英]Hover on svg for affecting the other element property doesn't work
HTML: HTML:
<div>
<svg class="velveti-grid-point" width="100" height="100" style="height: 120px; width: 625px;">
<circle class="myPoint" cx="500" cy="105" r="5" fill="#80E1EE" />
</svg>
<div class="theContainer">bg-color</div>
</div>
CSS: CSS:
.myPoint:hover + .theContainer {
background-color: black;
}
Problem: When i am hovering on the blue svg circle the background-color should be displayed on the text, but with svg it doesn't work. 问题:当我在蓝色svg圈上盘旋时,应该在文本上显示背景颜色,但是使用svg它不起作用。 What is the problem?
问题是什么? what do i need to do?
我需要做什么?
The demo: http://jsfiddle.net/wy6y66ox/ 演示: http : //jsfiddle.net/wy6y66ox/
This has nothing to do with SVG per se . 这与SVG 本身无关。
+
is referred to as an adjacent selector. +
被称为相邻选择器。 It will select only the element that is immediately preceded by the former element. 它将仅选择前一个元素前面的元素。
Because .myPoint
is not a sibling of .theContainer
your selector will not work. 因为
.myPoint
不是.myPoint
的兄弟, .theContainer
你的选择器不起作用。
You would need javascript in this instance. 在这个例子中你需要javascript。
Paulie_D is right.You have to use Javascript. Paulie_D是对的。你必须使用Javascript。
HTML HTML
<div>
<svg class="velveti-grid-point" width="100" height="100" style="height: 120px; width: 625px;">
<circle id="svgid" class="myPoint" cx="500" cy="105" r="5" fill="#80E1EE" />
</svg>
<div id="divcolor" class="theContainer">bg-color</div>
</div>
JS JS
var svg = document.getElementById( 'svgid' );
var div = document.getElementById( 'divcolor' );
svg.onmouseover = function() {
div.style.backgroundColor = 'blue';
};
svg.onmouseout = function() {
div.style.backgroundColor = 'transparent';
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.