jQuery SVG - 悬停元素



我正在尝试使用jQuery SVG插件 http://keith-wood.name/svg.html

一开始我就卡住了。我已经在那个圆圈上创建了一个简单的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

如果不希望文本响应鼠标

悬停,请将文本上的指针事件属性设置为 none,

例如
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'});

最新更新