1

我正在尝试使用 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

4

1 回答 1

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'});
于 2012-10-12T12:28:47.237 回答