簡體   English   中英

懸停在拉斐爾圓圈上時顯示文字

[英]showing text when hovering over a Raphael circle

我正在嘗試使用jQuery和RaphaelJS:

  • 創建圈子
  • 將鼠標懸停在圓圈上時顯示一些信息(並在未懸停在其上時隱藏信息)

但是,我無法正確顯示信息......它似乎顯示然后立即隱藏。 這是我正在使用的代碼的簡化測試版本:

<!DOCTYPE html>
<html>

<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="raphael.js"></script>
<script type="text/javascript">

$(function() {  
var paper = new Raphael("canvas_container", 300, 150);
paper.circle(50, 75, 30);
paper.circle(150, 75, 30);

$("circle").each(function(i) {
    $(this).mouseover(function() { 
        $("#test").append("<p>MouseOver</p>");
    });
    $(this).mouseout(function() { 
        $("#test").append("<p>MouseOut</p>");
    });
});
});
</script>
</head>

<body>
<div id="canvas_container"></div>  
<div id="test"></div>
</body>

</html>

在這個例子中,一旦我進入一個圓圈,立即顯示“MouseOver”和“MouseOut”。 我不確定我是否使用了錯誤的事件,或者拉斐爾是否有一些時髦的事情。

我是一個完整的Javascript noob,所以如果我只是以錯誤的方式做所有事情,那么我們非常感謝指針。

你真的離這里很近,但它只是在你越過圓圈的邊界時檢測到鼠標懸停和鼠標移動,因為它們沒有被填充。嘗試填充它們。

$(function() {  
var paper = new Raphael("canvas_container", 300, 150);
paper.circle(50, 75, 30);
paper.circle(150, 75, 30);

$("circle").each(function(i) {
    $(this).attr({fill: '#FFF', stroke: '#000'});
    $(this).mouseover(function() { 
        $("#test").append("<p>MouseOver</p>");
    });
    $(this).mouseout(function() { 
        $("#test").append("<p>MouseOut</p>");
    });
});
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM