javascript raphael对象函数传递

javascript raphael对象函数传递,javascript,raphael,Javascript,Raphael,我很抱歉问这个问题,但我只是想在今天早上得到一些指导。我只是想创建一个函数,这样我就可以通过传入一个Raphael元素使其发光。下面是我的代码。为什么这不起作用 var paper = Raphael("playarea", 500, 500); var rectangle = paper.rect(100, 100, 200, 200, 4); function elemHover(var el) { el.hover( // When the mouse comes o

我很抱歉问这个问题,但我只是想在今天早上得到一些指导。我只是想创建一个函数,这样我就可以通过传入一个Raphael元素使其发光。下面是我的代码。为什么这不起作用

var paper = Raphael("playarea", 500, 500);

var rectangle = paper.rect(100, 100, 200, 200, 4);

function elemHover(var el)
{

    el.hover(
    // When the mouse comes over the object //
    // Stock the created "glow" object in myCircle.g
   function() {
    this.g = this.glow({
        color: "#0000EE",
         width: 10,
         opacity: 0.8
     });
    },
    // When the mouse goes away //
    // this.g was already created. Destroy it!
    function() {
     this.g.remove();
    });
}

elemHover(rectangle);

这是小提琴

您应该
填充元素(本例中为矩形)以触发悬停

rectangle.attr("fill", "red");
试试这把小提琴

完整代码如下所示

<div id="playarea"></div>

​<script type="text/javascript">
var paper = Raphael("playarea", 500, 500);

var rectangle = paper.rect(100, 100, 200, 200, 4);

function elemHover(el)
{
    el.hover(
    // When the mouse comes over the object //
    // Stock the created "glow" object in myCircle.g
    function() {
     this.g = this.glow({
         color: "#0000EE",
         width: 10,
         opacity: 0.8
     });
    },
    // When the mouse goes away //
    // this.g was already created. Destroy it!
    function() {
     this.g.remove();
    });
}

rectangle.attr("fill", "red");

elemHover(rectangle);

</script>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

检查这里的提琴

你在JS控制台中看到任何错误吗?你能提供一个JSFIDLE演示吗?这里的提琴很好,它可以工作,但我不明白为什么需要矩形.attr才能工作。只有当元素被填充时才会触发悬停事件。答案已更新,包含此信息和透明元素的解决方案。我不知道。谢谢你的帮助。你今天保存了一台电脑。感觉很好。
rectangle.attr("fill", "transparent");