paso de función de objeto javascript raphael

I apologize for asking this question but I am just looking for a little guidance on this morning. I simply want to create a function so that way I can make a Raphael element glow by just passing in that element. Below is the code I have. Why does this not work?

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);

aquí está el violín http://jsfiddle.net/aZG6C/15/

preguntado el 31 de julio de 12 a las 14:07

Are you seeing any errors in your JS console? -

can you provide a jsfiddle demo ? -

aquí está el violín jsfiddle.net/aZG6C/15 -

1 Respuestas

Debes fill the element( rectangle in our case) to trigger the hover.

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

Prueba este violín http://jsfiddle.net/aZG6C/17/

El código completo se verá así

<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>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Noticias

Hover event is triggered only if the element is filled with something. If you want to have a transparent element you can try

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

Mira el violín aquí http://jsfiddle.net/aZG6C/20/

Respondido 31 Jul 12, 16:07

its great that it works but I don't understand why the rectangle.attr is required in order for this to work. - juanstew

Hover event is triggered only if the element is filled with something. Answer updated with this information and a workaround for transparent element. - kiranvj

didn't know that. appreciate the help. you saved a computer today. feel good about it. - juanstew

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.