Raphael JS Path Animation: Wiping Away

I have successfully created a line animation using RaphaelJS, which can be viewed on this jsfiddle link - http://jsfiddle.net/7n040zdu/. My next challenge is to create an erasing animation that follows the initial one. This erasing animation should mimic the initial animation by moving along the same path at the same speed and direction.

My attempt to overlay another path for the erasing effect did not yield the desired result. If the original path overlaps with the erasing path, it becomes apparent that the animation is not truly 'erasing' but rather getting covered up.

I have searched through the Raphael documentation but have not found a suitable solution for achieving this effect.

Here is the relevant code:

HTML

<body>
<div class='drawings' id="draw0"></div>
</body>

CSS

body {
    background-color: black;
}

JS

var animateLine = function(canvas, colorNumber, strokeWidth, pathString) {
    var line = canvas.path(pathString).attr({
        stroke: colorNumber
    });

    var length = line.getTotalLength();

    $('path[fill*="none"]').animate({
        'to' : 1
    }, {
        duration: 1000,
        step: function (pos, fx) {
            var offset = length * fx.pos;
            var subpath = line.getSubpath(0, offset);
            canvas.clear();
            canvas.path(subpath).attr({
                stroke: colorNumber,
                "stroke-dasharray" : "",
                "stroke-width" : strokeWidth
            });
        }
    });
}

var canvas = new Raphael('draw0', 50,50);
var drawPath1 = 'M0.767,0.915 M48.538,20.228L0.767,0.915l3.896,39.312L48.538,20.228L37.663';

animateLine(canvas, '#FFF', '1.5', drawPath1);

Answer №1

After receiving feedback from @Ian on the original question, I successfully implemented a single path and animated the dashoffset of the svg. However, it required additional modifications to ensure it worked correctly.

Initially, the CSS for the SVG path is defined with the parameters: 'stroke-dasharray': '9999px' and 'stroke-dashoffset': '9999px'. The animation then involves transitioning the stroke-dashoffset from 9999px to 9999px minus the length of the path. Once this initial animation is complete, the CSS needs to be updated again to: 'stroke-dasharray': '999 999' and 'stroke-dashoffset': '9999px'. Subsequently, the stroke-dashoffset is animated once more, but this time as

'stroke-dashoffset': (9999-(length of path)-100)+'px'
.

You can view a demonstration of this process in a jsfiddle here: http://jsfiddle.net/tim_m/94ze4ajj/

*Please note that in the jsfiddle example, I included additional paths with varying opacity and time offsets to create a fading effect at the ends of the line animation.

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

Tips for resolving the problem of Google Maps repeatedly appearing when utilizing the Auto-Loading feature

I need help understanding the issue that arose when loading the Google Maps API. "You have included the Google Maps API multiple times on this page. This may cause unexpected errors." This error occurred while attempting to automatically load the API. B ...

How can function expressions result in a returned value?

Function expressions result in a value, unlike function declarations which do not. This distinction was clarified for me by others in a different SO thread (link provided). All functions default to returning undefined, hence the emphasis on "expression" ...

Unusual conduct exhibited by jQuery's css() function for setting the width

My goal is to retrieve the width of the initial .imagen element and apply it to the img within .imagen. HTML: <div class="imagen"> <div class="normal"> <img> </div> <div class="hover"> <img> ...

I'm having issues with my pop method - it doesn't seem

Hello everyone, I am new to core JavaScript and currently learning how to create an array. I have written the following code but for some reason, the pop method is not working as expected. var players=['david','micky','Ryan' ...

Changes to the state will not be reflected until a poll is conducted

Here we have an example of state being initialized and passed down to a child component: const [rowCount, setRowCount] = React.useState<number>(1); <Foo setRowCount={setRowCount} /> Foo: const Foo = (props) => { const { setRowCount } ...

Having trouble passing multiple parameters in a jQuery AJAX request?

I'm currently working on implementing a .NET web service (asmx) using JSONP with guidance from this helpful tutorial. When I try calling my webservice with only one parameter, everything runs smoothly. However, the moment I attempt to call it with mu ...

Vuex has reserved this keyword

I am working on a Laravel application with the following code in app.js: require('./bootstrap'); window.Vue = require('vue'); import { store } from './store/store' import Sidebar from './Sidebar' Vue.component(& ...

Prevent parent element from triggering double click when double clicking on children element with CSS or jQuery

Check out my project demo here Whenever I double click on a child element, it also triggers the parent element at the same time. I want to prevent this behavior so that only the child element is affected by the double click event. Can anyone provide assis ...

Comparing two datetime objects with time zone offsets in JavaScript: How to determine if one is greater than or less than the other?

So I'm faced with a situation where I need to compare two dates where the first date is 05.01.2008 6:00 +5:00 and the second date is 05.01.2008 7:00 +5:00 I'm struggling to find a way to convert these datetimeoffsets into a specific forma ...

Efficiently sorting items by category name in PHP with Ajax

Currently, I am working on a functionality that involves two dropdown lists. The first one, located at the top, is for selecting a category of meals. Each option in this dropdown has an associated id_cat value. <option value="1">Pâtis ...

Utilizing service-based global objects in Angular applications

Upon entry into my application, the GlobalApplicationController initializes several services that are utilized throughout the entire application, such as subscribing to sockets. It would be quite beneficial to have a CurrentUser object available - however, ...

transferring double quotation marks and square brackets through a parameter

I have an angularjs (1.x) scope set up as follows: $scope.report = { resource: '/public/emplyACH', params: { "employeeId": [78] } }; When I try to access it using console.log (console.log(scope.parms)) I see the output as ...

Error in Google reCaptcha 2: "a is null" occurs when grecaptcha.reset function is executed

I am currently working on a registration page that utilizes AJAX for validation on both the client and server sides. If the server side validation fails, the AJAX function returns the errors to the screen and tries to reset the reCAPTCHA using grecaptcha. ...

Error: JSON encountered circular structure when attempting to serialize an object of type 'ClientRequest' with a property 'socket' that references an object of type 'Socket'

Encountering an error while attempting to make a POST request to my TypeORM API using axios: TypeError: Converting circular structure to JSON --> starting at object with constructor 'ClientRequest' | property 'socket' -&g ...

Invoke the designated JavaScript function within a subordinate <frame>

Below is an example of the standard HTML structure for a parent page named "index.html": <html> <head> <title>test title</title> </head> <frameset cols="150,*"> <frame name="left" src="testleft.html"> ...

AngularJS promise fails to resolve when attempting to read a file using the FileReader

Can someone assist me with a function I am trying to create in my service? I want the function to use FileReader to read a small image file and return the result in a promise to my controller. The issue is that while the file reaches the service without an ...

Infinite Scrolling in React: Troubleshooting Issues with the dataLength Parameter

A function called newsFeed is utilized within the useEffect hook to make a request to an endpoint for fetching posts made by the logged in user and users they follow. The retrieved data is then saved to the state: const [posts, setPosts] = useState([]) con ...

Parsing JSON data repeatedly using JavaScript within an HTML environment

The following code I found on a popular web development website works perfectly: <!DOCTYPE html> <html> <body> <h1>Customers</h1> <div id="id01"></div> <script> var xmlhttp = new XMLHttpRequest(); var url ...

flexanimate functioning only on the first attempt

I've been attempting to use jQuery and AngularJS to control the movement of a flex slider using keyboard input. However, I am finding that it only works once with FlexAnimate and then stops working. Can anyone offer insight as to why it is not functio ...

Tips for implementing this jQuery functionality within an AngularJS directive

How can I incorporate this jQuery code into my Angular project? jQuery.prototype.stars = function() { return $(this).each(function() { var val = parseFloat($(this).html()); var size = Math.max(0, (Math.min(5, val))) * 16; var $span = $ ...