[英]How can I make a div appear when hovering over a SVG path?
I'm working on this SVG image , jsfiddle 我正在处理此SVG图像jsfiddle
<div id='one'>
items that should appear when hovering over 01(red circle) on the svg image
</div>
<div id='two'>
items that should appear when hovering over 02(green circle) on the svg image
</div>
<div id='three'>
items that should appear when hovering over 03(purple circle) on the svg image
</div>
I need the div appear when hovering over the relevant SVG circle , and the circle should be highlighted when hovering over it, 我需要将div悬停在相关的SVG圆上时出现,并且将圆悬停在相应的SVG圆上时应突出显示该圆,
I'm new to JS and don't know where to start , I looked for libraries like SVG.js and vivus.js but they are too complicated for this small task , please help me out , thanks 我是JS的新手,不知道从哪里开始,我在寻找SVG.js和vivus.js之类的库,但是它们对于这个小任务来说太复杂了,请帮帮我,谢谢
Using jQuery, show/hide a div when the mouse enters and leaves the desired circle respectively. 使用jQuery,当鼠标分别进入和离开所需的圆圈时,显示/隐藏div。
Below is the snippet for div toggle and see the working fiddle 以下是div切换的代码段,请参阅工作提琴
JS JS
$(function() {
$("#XMLID_359_").hover(function(){
$('#one').toggle();
$(this).addClass('transform');
});
$("#XMLID_362_").hover(function(){
$('#two').toggle();
$(this).addClass('transform');
});
$("#XMLID_67_").hover(function(){
$('#three').toggle();
$(this).addClass('transform');
});
$("#XMLID_359_,#XMLID_362_, #XMLID_67_").mouseleave(function(){
$(this).removeClass('transform');
});
});
CSS CSS
#one, #two, #three{
display: none;
}
#XMLID_359_, #XMLID_362_, #XMLID_67_{
transition: all 200ms ease-in;
}
.transform{
transform: scale(1.1, 1.1);
}
#XMLID_362_.transform{
transform: scale(1.1, 1.1) translateX(-72.3px);
}
You would have to include the jQuery library in the application. 您将不得不在应用程序中包括jQuery库。
Try following code 尝试以下代码
function showMe1(){ document.getElementById('one').style.color=""; } function showMe2(){ document.getElementById('two').style.color=""; } function showMe3(){ document.getElementById('three').style.color=""; } document.getElementById('one').style.color="transparent"; document.getElementById('two').style.color="transparent"; document.getElementById('three').style.color="transparent";
div:hover { visibility: visible; }
<div id='one' onmouseover="showMe1()"> items that should appear when hovering over 01(red circle) on the svg image </div> <div id='two' onmouseover="showMe2()"> items that should appear when hovering over 02(green circle) on the svg image </div> <div id='three' onmouseover="showMe3()"> items that should appear when hovering over 03(purple circle) on the svg image </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.