almende / vis

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
7.86k stars 1.48k forks source link

Network animation on load #2306

Closed TJRL closed 7 years ago

TJRL commented 7 years ago

Hi, I'd like to add a fly in animation on the network, starting very much zoomed in on one node, than zooming out to fit. However, it should run only once, when the page is loaded. I tried to set the initial zoom level with the beforeDrawing event, but that event triggers apparently over and over again, which makes it return to this position each time you try to move or zoom out.

network.on("beforeDrawing", function() {  
  network.focus(0, {scale:7});
});

I also tried with javacript window.onload, but I think that triggers too early, so nothing happens.

Any suggestions how to do this?

TJRL commented 7 years ago

Ah! Solved it myself already. Rather than network.on I should use network.once! So, this is what I got to make the animation start automatically and play once:

network.once("beforeDrawing", function() {
network.focus(0, {scale:10});
});
network.once("afterDrawing", function(){
network.fit({animation: {duration:2500, easingFunction: 'easeOutQuint'}});
});
mojoaxel commented 7 years ago

@TJRL That sounds interesting!! Maybe you can create a simple example that demonstrates this? We would be more than happy to include it in the examples.

TJRL commented 7 years ago

Sure!

https://jsfiddle.net/Thymus82/paxeppmv/18/

yotamberk commented 7 years ago

Added with #2476