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

Use javascript/ajax to submit the form on a separate page

I'm trying to use ajax to submit a form on another page, but my code doesn't seem to be working. Here is what I have: Send(); function Send() { var abc = document.getElementsByClassName("main"); for (var i = 0; i < abc.length; i++) { var ...

Adjustments in margins for printed HTML may vary from page to page in Internet Explorer versions 8 to 11

One challenge I'm facing is with a user-generated report page that is typically printed. There seems to be an unusual bug occurring specifically in Internet Explorer. The layout of the page consists of tables within various divs, all aligned perfectly ...

Bookmarklet in JavaScript that automatically extracts and displays Meta keywords in a new tab within the browser

I successfully implemented a script that extracts site meta keywords and writes them into the DOM. javascript:(function metaKeywords() { metaCollection = document.getElementsByTagName('meta'); for (i=0;i<metaCollection.length;i++) { nameAttri ...

Dealing with preventing form submission in JQuery due to the use of Char(13) causing newline issues

Currently, I am facing an issue with capturing the class for my address field. I have successfully prevented the enter key (char[13]) from submitting the form. However, I now need to make an exception for text blocks, such as the address field, where I wan ...

Difficulties with toggling jQuery menus

I am trying to create a sidebar that will appear with a full screen fade over the entire page when I click on the 'navigate' text. Currently, the sidebar appears and my header text moves to the left. However, I am struggling to make it responsiv ...

What is the best way to eliminate the extra spacing on the right side of my navigation bar?

Hello everyone! I am diving into the world of HTML and CSS, but I've hit a roadblock. Despite searching through various resources and forums, I can't seem to find a solution to my problem. The issue at hand involves an irritating space in my nav ...

"Function.click operates successfully when no arguments are given, but encounters issues when arguments are supplied

I had a function that was functioning correctly: $('#buttFurniture').click(onFilterCLick); However, when I decided to pass arguments to the function, it stopped working: $('#buttFurniture').click(onFilterCLick(arrOutput, arrFurniture ...

How to transmit data from a button click using Ajax/jquery without the need to refresh the page

I've been struggling for hours to make this work and haven't made any progress. What I'm attempting to accomplish is sending a URL when a button is clicked, without refreshing the page. PHP code for the button: echo '<a href=" ...

Is your text appearing vertically in Internet Explorer?

I'm having an issue with my small single page website where the text in a form is displaying vertically instead of horizontally in Internet Explorer. The problematic part is related to "vehicle condition." Any suggestions on what I might be doing wron ...

jQuery is experiencing compatibility issues with node-webkit

Currently, I am experimenting with node-webkit as a beginner in nodejs. The main content of my webpage consists of a simple html page which includes a script called main.js. To install jquery, I used the command npm install jquery index.html <!-- i ...

Ways to delete a class if it currently exists?

Is there a way to manage multiple toggle classes within a single div? It can be frustrating when clicking the maximize or close button triggers the minimize function as well. How can this situation be addressed? Is there a way to manage multiple toggle cl ...

Several buttons converging towards a single circle

I attempted to create a circular layout using 6 buttons, but the end result did not form a perfect circle as intended. In the image provided, I highlighted the areas of concern in red. Below, you will find my HTML and CSS code for reference. <!DOCTYP ...

The style from 'http://localhost:2000/cssFile/style.css' was rejected because its MIME type was 'text/html'

Currently, I am attempting to include my style.css file in the home.ejs file being rendered by express.js. However, I keep encountering the following error: Refused to apply style from 'http://localhost:2000/cssFile/style.css' because its MIME t ...

What is the best way to display values from a Localstorage array in a tabular format using a looping structure

I have set up a local storage key 'fsubs' to store form submissions as an array. Here is how I am doing it: var fsubs = JSON.parse(localStorage.getItem('fsubs') || "[]"); var fcodes = {"barcodeno" : this.form.value.barcode, "reelno" : ...

Utilizing Vue-i18n for language translations directly within a JavaScript file, rather than using

Is there a way to utilize the .js file for translations instead of the .json file? I attempted changing: const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i) to const locales = require.context('./loca ...

Send back alternate HTML content if the request is not made via AJAX

Last time I asked this question, I received several negative responses. This time, I will try to be more clear. Here is the structure of a website: Mainpage (Containing all resources and scripts) All Other pages (HTML only consists of elements of that ...

Is there a way to effortlessly refresh the WooCommerce cart and receive updated HTML content all in one go?

I am currently working on a customized "mini-cart" that mimics the functionality of the main cart page, including options to adjust quantity, remove items, enter coupons, and remove coupons. I have set up the cart to submit changes via Ajax by listening fo ...

js include exclude switch a category

Although this question has been asked before, I have a query on completely removing an "id" from an element. Let's consider the following scenario: <div id="page"> some content here </div> I want to eliminate the "id" attribute from the ...

Navigating to a particular div using a click event

I am trying to achieve a scrolling effect on my webpage by clicking a button that will target a specific div with the class "second". Currently, I have implemented this functionality using jQuery but I am curious about how to accomplish the same task using ...

Addressing the issue with this.setState and this.state on the Registration page

I am facing an issue with my Registration Page code. I am trying to send data to a database using this.setState and this.state, but every time I run the code, it shows an error in the onSubmit function related to this.state. Can someone please help me unde ...