2012-10-12 64 views
1

我试图使用jQuery插件SVG http://keith-wood.name/svg.htmljQuery的SVG - 悬停元素

而且在一开始我stucked。我已经在该圆圈上创建了一个简单的svg.circle和svg.text 。我想在鼠标悬停在圆上时给出一些动画。它的工作原理,但当我移动鼠标指针上的文字悬停状态是关闭的。这是正确的行为,但如何强制这种悬停状态,而鼠标获取文本?

这是代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> 
<title>jQuery SVG Basics</title> 
<style type="text/css"> 
#svgbasics { width: 400px; height: 300px; border: 1px solid #484; font-family: Tahoma; font-size: 50px; } 
</style> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
<script type="text/javascript" src="jquery.svg.js"></script> 
<script type="text/javascript" src="jquery.svganim.min.js"></script> 
<script type="text/javascript" src="jquery.svgfilter.js"></script> 
<script type="text/javascript"> 

$(function() { 
    $('#svgbasics').svg({onLoad: drawInitial}); 
}); 

function drawInitial(svg) { 

    var mycircle = svg.circle(75, 75, 50, {fill: '#f2477b', stroke: 'none', 'stroke-width': 0}); 
    var mytext = svg.text(52, 76, 'SVG', {'font-family':"Verdana", 'font-size':20, 'text-anchor':'middle', 'fill':'#fff', 'cursor': 'pointer'}); 

    $(mycircle).hover(function() { 
     $(this).css("cursor", "pointer"); 
     $(mycircle).animate({svgR: 45, svgStrokeWidth: 4, svgStroke: '#f882a6'}, 100); 
    }, function() { 
     $(mycircle).animate({svgR: 50, svgStrokeWidth: 0, svgStroke: 'none'}, 100); 
    }); 
} 
</script> 
</head> 
<body> 
<div id="svgbasics"></div> 
</body> 
</html> 

这是代码的结果:http://goo.gl/RwRw0

回答

5

设置指针的事件属性设置为无上的文字,如果你不希望它回应鼠标悬停在例如

var mytext = svg.text(52, 76, 'SVG', {'font-family':"Verdana", 'font-size':20, 'text-anchor':'middle', 'fill':'#fff', 'cursor': 'pointer'}); 

成为

var mytext = svg.text(52, 76, 'SVG', {'font-family':"Verdana", 'font-size':20, 'text-anchor':'middle', 'fill':'#fff', 'cursor': 'pointer', 'pointer-events', 'none'}); 
+0

谢谢罗伯特,它就像魅力:) – David

+0

顺便说一句,这是一个CSS属性,它是如此有线我从来没有听说过这件事,反正再次感谢名单 – David