Dynamic animation utilizing Angular JS and Snap SVG

Attempting to achieve a seamless and continuous animation using AngularJS and Snap SVG, I believed I had successfully resolved the issue as my animations ran smoothly for hours on end. However, leaving my solution running over the weekend in Chrome, Opera, Safari, and Firefox (where Internet Explorer failed to run it at all), I encountered crashes on Firefox and Opera upon returning to work this morning, with Chrome and Safari pages frozen.

The animation functions in question are as follows:

        /* defining the hub's center in the drawing */
        var hubCenter = "269, 367";

        /* time taken to complete an animation move */
        var moveTime = 100;

        /* name of the Angular module I'm creating */ 
        var turbineApp = angular.module('spinningTurbine', []);

        /* controller for that module */
        turbineApp.controller('turbineController', ['$scope', function ($scope) {
            $scope.speed = 0;
            $scope.angle = 0;
            $scope.height = 150;

            /**
             * Rotate the element with the specified tag around the hub center location
             * to reflect the specified value.
             */
            $scope.sweep = function( tag, angle) {
                var elt = Snap(tag);

                var directive = "r" + angle + ", " + hubCenter;

                elt.animate({
                    transform: directive
                }, moveTime);
            }

            function spinner() {
                setTimeout( function() {
                    $scope.angle += parseFloat($scope.speed);
                    $scope.sweep( '#blades', $scope.angle);
                    spinner();
                }, moveTime);
            }       

            spinner();
        }]);

My inquiry pertains to whether the JavaScript setTimeout() function uses up resources (e.g., stack) or if Snap SVG is utilizing resources by continually expanding the transformation path.

I aim for this animation to operate indefinitely, thus necessitating either identifying the cause of browser crashes or reconfiguring it with an alternate method. Are there other mechanisms in Angular JS for executing a non-terminating loop?

Answer №1

Is it more advantageous to employ the $interval() method?

$interval(function() {
                   ... Execute Exciting Actions in this section
                }, moveTime);

Incorporating it into your controller is essential for functionality.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to querying JSON data in a backend database with JavaScript

My backend JSON DB is hosted on http://localhost:3000/user and contains the following data: db.json { "user": [ { "id": 1, "name": "Stephen", "profile": "[Unsplash URL Placehol ...

Trouble with React Material Modal TransitionProps triggering onEntering event

Currently, I am in the process of updating Material UI to version 5. Initially, I encountered an error stating that onEntering is deprecated and should be replaced with transitionprops. There is a specific method (let's name it doSomething) that I wa ...

Tips for showcasing a personalized design using ng-repeat

Upon reflection, I realized that my original question needed improvement, so here is the revised version. Hello! I am new to Angular and I am attempting to create a custom layout for my data list using ng-repeat. I want to display different model values w ...

Protractor is unable to interact with the embedded <span> within the <a> tag

I am facing an issue where I have two nested <span> elements inside an <a> tag. My objective is to trigger a click event on the second <span>. I tried using the by.id method on the custom classes I created, but it did not work. I also att ...

Guide on transferring text from .txt document to .xlsx file in a Node.js environment with the assistance of the xlsx library

I recently extracted names from my cypress test and stored them in a text file called 'name.txt' located in the root directory of my project. Now, I am looking to transfer all the text from 'name.txt' into an excel file named 'qaau ...

How can we choose a specific array object that correlates with another?

Imagine you have an array named "test" and it's defined as var test = [1, 2, 3, 4];. Is there a method to specifically select the number 2 based on the condition that it is less than 3? If my explanation wasn't clear enough, please let me know w ...

Is it possible to transform an arrow function into a regular function?

Currently, I am working my way through the AJAX type ahead course in Javascript 30 by Wes Bos. As I progress through this course, I have made a conscious effort to minimize my use of ES6 features for the sake of honing my skills. If you want to see the fi ...

In Angular Typeahead, the model is used as an identifier and the Text represents the name in the array object

I'm currently utilizing the Angular UI Typeahead directive available at this link. Can someone provide guidance on how to assign a model as an id and display text as a name in it? I have attempted the method below but encountered issues. Any suggestio ...

Encountering a problem with controlling the number of splits allowed

I am encountering an issue with splitting my string using the code below. splitter.map((item1) => { let splitter1 = item1.split("=")[0].trimLeft(); let splitter2 = item1.split("=")[1].trimRight(); }); The content of item1 is as fo ...

Having trouble with the dropdown onclick event not triggering when an item is selected in React?

I am having an issue where the onclick event handler is not being called when a dropdown item is selected. In my code, I am generating a dropdown inside a loop in the componentDidMount() lifecycle method. I am passing an event handler function named "show ...

Driving a Car using THREE.js on the Highway

I'm currently developing a car game using THREE.js. I've encountered an issue where I have created a road using Plane geometry and placed the car on it. Now, I have also made a terrain but am unsure of how to link the car to the road so that it m ...

"Adjust the placement of a personalized marker on a Google Map using google-map-react

I have incorporated google-map-react into my React project and I have designed custom markers. The markers are displayed at the correct location but from the top left corner: https://i.sstatic.net/e6lGN.png The red dot indicates the exact location. Howe ...

Ways to access component load status in Next.js

I'm currently developing a basic Pokedex to showcase all Pokemon. I am utilizing a map function on an array of Pokemon objects to display all the cards in this manner: {pokemons.results.map((el, i) => { return ( <di ...

Tips on implementing .on() with querySelector in jquery?

Can you help me convert the jQuery code below into a querySelector method? <script type="text/javascript"> jQuery(function($){ $('#woocommerce-product-data').on('woocommerce_variations_loaded', function() { $ ...

JavaScript is reporting that the length of the array is not defined, rather than the array itself

My goal is to utilize data from the Politifact API by saving it in an array named "superArray." I achieve this by making three API calls and adding 10 values from each response to superArray, as shown below: const URL1 = "https://www.politifa ...

The server is receiving empty values from the Ajax post

I'm attempting to extract an image file from a base64 string received from the client side. Here is the ajax post I'm using: $.ajax({type: "POST", url: "upload_post.php", data: postData, dataType: "text", success: function(result){ ale ...

send data from the front-end to the back-end

I'm working on a Vue.js project with frontend, and I have a field containing variables that need to be updated in the backend when changed. Any ideas on how to achieve this? The variable in question is an ID tag, as shown in the following code snippet ...

Are Lazily Instantiated Singletons a Thing in AngularJS?

After browsing through the AngularJS documentation, I came across an interesting detail about AngularJS services: AngularJS lazily instantiates services, meaning they are only created when a component in the application requires it. Services in AngularJ ...

Remove the bottom border from the active tab by utilizing the <div> and <a> elements

I am facing an issue with a tabbed menu on my webpage. While the menu is functioning correctly, I am struggling to remove the bottom border from the active tab. You can view all of my test code here. While I have come across solutions using <ul> an ...

Hiding a div using swipe gestures in Angular

What am I trying to achieve? I aim to hide a div when swiped right. This specific action will close the pop-up that appears after clicking a button. What tools are at my disposal? I am utilizing Ionic framework for this task. Within my app.js, I have i ...