7

Is there a way to make element fade in or fade out using Raphael.js? My code is something like:

var elem = paper.circle(10, 10, 10)
elem.hide();

Is there an attribute to .hide() to make fade effect, something like:

var elem = paper.circle(10, 10, 10)
elem.hide({'duration':5000});
Demeter
  • 106
  • 1
  • 8

2 Answers2

13

You can animate opacity for fade effect

var elem = paper.circle(10, 10, 10);
elem.animate({ opacity : 0 }, 1000, function () { this.hide() });

To fadeIn,

elem.show().animate({ opacity : 1 }, 1000);

Jashwant
  • 28,410
  • 16
  • 70
  • 105
4

You can do it without animations also: http://jsfiddle.net/3jsFe/1/

You need to take the elem.node

$(elem.node).fadeOut(2000, function() {
    $(elem.node).fadeIn(2000);
});
Ron van der Heijden
  • 14,803
  • 7
  • 58
  • 82
  • So, `elem.node` selects the xml node and then you can use jQuery over that ? +1 – Jashwant May 07 '13 at 08:37
  • Yes, you can use jQuery for fade's, animations, and everything else what jQuery does. Using `elem.node` you take the node element and you can manipulate with it. You also could use (like Jashwant answered) [elem.animate](http://raphaeljs.com/reference.html#Element.animate) but I prefer jQuery because I'm already used to it. :) – Ron van der Heijden May 07 '13 at 08:54