Javascript on ajax keeps growing

I have a site with a configurable 3d object which has some properties and as i change those properties I reload the div with 3d object to reflect new properties. It works fine except that the script data keeps adding on. Not only the script slows down after 30 reloads, but here is what happens. I added rotation object rotation to rendering function and with every reload the button keeps spinning faster! After 5 reloads it spins like crazy. The spinning function is simple:

    function animate() {
    if (typeof(objektas) !== 'undefined') {
        if (rotation >= 360) rotation = 0;
        objektas.rotation.y = rotation * Math.PI * 2 / 360;
    requestAnimationFrame(animate, renderer.domElement);
    renderer.render(scene, camera);

My guess is that with every load render those animate functions are stacked and for example in second reload they are called twice instead of once. Can somebody explain how can I solve this issue?

Source: ajax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.