In this tutorial, I will show you how to add an animated line that goes from element to element, across your entire Elementor page.
With this method, the line is generated automatically, so you don't even have to worry about creating properly sized SVG lines in illustrator.
This method is very user friendly and easy to replicate and work with!
Here is what you will learn:
Features:
- Polyvalent: Works for any amount of lines
- Responsive: Works well on desktop, tablet and mobile
- Customizable: Set the size and color of the line as you wish, as well as the animation duration
- LeaderLineJS: We are using the LeaderLineJS library for this
- Easy to replicate: Set from and to elements, and the line is drawn in-between these
- Works for various layouts: In my demo I have a simple layout based on cards, however you can trace the line from any element, to any element, so this can be quite flexible and work with different kinds of designs
Let's get started!
First, let's add the required code to your page
This is a premium tutorial. Purchase access to unlock the full tutorial.
13 Responses
Awesome! As a variation, is there a way to connect the tracing of the line to the scroll? So that if you scroll down, the line is traced, and if you scroll up, the line is "untraced"?
Greetings!
Unfortunately this isn't possible with this tutorial and the JS library used here.
To be frank though, unless you are going to add smooth scrolling (which is rarely a good idea as it's scroll jacking), I found that having the whole line trace in one animation is more pleasant and smoother.
Cheers!
Greetings everyone!
I was asked if it was possible to set specific customSettings for tablet and mobile too, instead of just reverting back to 'auto' everything, and stacking it all.
Yes it is! Here is how you can do that.
I didn't add these instructions directly in the tutorial to prevent making it too complicated.
At the start, you have the leaderLines JavaScript array:
Directly below, add this:
And then, update these leaderLines JavaScript arrays with the settings of your choice, for each viewport.
You will have to repeat each setting! You can't just update those you want different... so you have to enter again every setting for every line.
In other words, if you originally had 8 lines, then you will need the same 'from' and 'to' in the tablet and mobile settings too. The customSettings can be different however. [To be very technical, if you wanted to, you could in fact even change the 'from' and 'to', if you wanted the line to go to and from different elements on different viewports.]
Finally, you also need to change this line:
to
Keep in mind, this won't update on window resize. It will only work on page load. So for instance, if you open the page in your browser, and then check with the DevTools responsive preview mode, you will need to refresh the page to see the mobile settings in action.
I hope this helps!
Cheers!
Hey Maxime
So I love this design, but I wonder if there is an option to change the leaderline? The only solution I've found so far is to change the line through CSS but that seems to create a hitch in the animation...
I used the following to make the line into a dot:
.leader-line use {
stroke-linecap: round;
stroke-dasharray: 0, 16;
}
But it seems to conflict with the dynamic dashoffset... Is there a way to alliate this issue?
Hey Jeremie!
Ignore my previous comment. It just isn't working....
The only way I found is to change the CSS until the animation matches:
.leader-line use {
stroke-linecap: round;
stroke-dasharray: 0, 24;
}
But then the dotted line is different too...
Downloaded and uploaded to my page but could not get it to show.
Please share your URL with me I will have a look.
It finally kicked in. Up loaded it 3 times before I got it to work, not sure what was up. Is there anyway to get these to show in editor mode? Would be so much easy to adjust styles.
Sorry it's not possible to run it in the editor...
Hey Maxime,
Sorry if this is beyond the tutorial. The story line works great, our art director is using it in a bunch of places. It's just what we need. But, for one of the layouts, we're trying to use it with sticky columns. It works fine on page load but then it gets...lost. Is there anything you might recommend? Like is there a way to make it disappear after it animates maybe?
Thanks!
Greetings Lesley!
Near the end of the JavaScript, just after the line that says
initLeaderLines();
try adding this:
Here I excluded mobile devices as probably you don't have the sticky column there.
Cheers!
Thanks, Maxime! That works great, it stays connected to both elements perfectly.
Thanks so much for the help!