Nicely done. Especially with the smooth quadratic curve.
You could consider moving a lot of this into a class in order to keep it out of global scope. Also, though it works, I think it's a little awkward to call functions before they are defined. I like to place my event listeners all together at the end of a code block.
Hey Rich! It all makes perfect sense, thank you for the code review! I do have a tendency to concentrate on the visual aspect so it's always nice to have someone to take a look at my JS
Senior Full-stack .Net Developer who has Created and optimized scalable web applications for over 8 years ,leveraged troubleshooting and
debugging expertise to contribute to the successful development
Leading provider of intuitive and powerful APIs designed for seamless business integration. With a focus on real-time, accurate data, aiming to drive operational efficiency and decision-making for its
@uuuuuulala, so have very tasteful people in your life :)
I discovered your "Damn Satisfying" (and it really is) Curly Cursor creation on CodePen, then had to hunt down my DEV login info, just so I could comment on what beautiful art/code you've made. AND- thank you for also taking the time to write up the tutorial!
Omg @lorenmcclaflin thank you so much!
It took me a bit of time to notice your comment but I'm soooo happy to see it now :) Really made my day, thanks man
I don't think processing.js has been actively maintained for quite some time. That was replaced by p5.js but TBH I think they tried too hard to match processing's Java based syntax in js; which I found rather limiting.
For anything canvas based my preference these days is pixiJS :)
I am using Wix and have been trying to add this to my website for the past 4 hours... completely new to code and no clue where to start. How would this be formatted for HTML? Thank you!
Your issue is not about the animation itself but rather about getting correct pointer position. pointer.x and pointer.y properties should be calculated ** relative** to the <canvas> element.
In the original demo, <canvas> has a full-screen size, and <canvas> position is set to fixed (see CSS code). In this setup, we can track cursor position simply using e.pageX and e.pageY properties (see event listeners in the JS code).
But if <canvas> position isn't fixed and there are other HTML elements above the animation, you need to take into account the top offset of <canvas> itself
There're different ways to do so, for example
canvas.addEventListener("click",e=>{updateMousePosition(e.clientX,e.clientY);});canvas.addEventListener("mousemove",e=>{mouseMoved=true;updateMousePosition(e.clientX,e.clientY);});canvas.addEventListener("touchmove",e=>{mouseMoved=true;updateMousePosition(e.targetTouches[0].clientX,e.targetTouches[0].clientY);});functionupdateMousePosition(eX,eY){constbox=canvas.getBoundingClientRect();pointer.x=eX-box.left;// take into account horizontal position of canvaspointer.y=eY-box.top;// take into account vertical position of canvas}
You can google "pointer position relative to element" to learn about the topic
We're a place where coders share, stay up-to-date and grow their careers.
Nicely done. Especially with the smooth quadratic curve.
You could consider moving a lot of this into a class in order to keep it out of global scope. Also, though it works, I think it's a little awkward to call functions before they are defined. I like to place my event listeners all together at the end of a code block.
Hey Rich! It all makes perfect sense, thank you for the code review! I do have a tendency to concentrate on the visual aspect so it's always nice to have someone to take a look at my JS
Great Project 👍
Thanks man
amazing
Nice project
Soooooo satisfying! I can spend hours playing around with this!
amazing job
@uuuuuulala, so have very tasteful people in your life :)
I discovered your "Damn Satisfying" (and it really is) Curly Cursor creation on CodePen, then had to hunt down my DEV login info, just so I could comment on what beautiful art/code you've made. AND- thank you for also taking the time to write up the tutorial!
Omg @lorenmcclaflin thank you so much!
It took me a bit of time to notice your comment but I'm soooo happy to see it now :) Really made my day, thanks man
Very nice, thank you
Look at processing.js...
I don't think processing.js has been actively maintained for quite some time. That was replaced by p5.js but TBH I think they tried too hard to match processing's Java based syntax in js; which I found rather limiting.
For anything canvas based my preference these days is pixiJS :)
PixiJS is indeed a great library
May I also suggest PaperJS
this is the uprgarted version of that code in only html
<!DOCTYPE html>
Interactive Cursor Tutorial
<br>
/* Resetting default styles and adding custom styles <em>/<br>
body,<br>
html {<br>
padding: 0;<br>
margin: 0;<br>
overscroll-behavior: none;<br>
background-color: #111; /</em> Dark background color <em>/<br>
color: #fff; /</em> Text color /<br>
}</p>
<div class="highlight"><pre class="highlight plaintext"><code> / Styling for the tutorial link */
.links {
position: fixed;
bottom: 10px;
right: 10px;
font-size: 18px;
font-family: sans-serif;
background-color: white;
padding: 10px;
}
</style>
</code></pre></div>
<p></head></p>
<p><body><br>
<!-- Canvas element for the interactive cursor animation --><br>
<canvas></canvas></p>
<div class="highlight"><pre class="highlight plaintext"><code><!-- Tutorial link with icon -->
<div class="links">
<a href="dev.to/uuuuuulala/coding-an-intera..." target="_blank">tutorial<img class="icon" src="https://ksenia-k.com/img/icons/link.svg"&gt;&lt;/a&gt;
</div>
<!-- JavaScript for interactive cursor animation -->
<script>
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext('2d');
</script>
</code></pre></div>
<p></body></p>
<p></html></p>
<p>this is only html but fully working try thanks me latter</p>
How would you format this so it is ready to use? I am completely new to code and don't even know where to start!
How can I shorten it?
May I know if there is any way I can change the colour of the ink? Sorry I am a beginner
it's very simple to do, just add a
strokeStyleproperty to the Canvas context, for exampleLearn more about styles and colors here
Thank you you are amazing
What a lovely effect and I really like the code explanation. It was easy to understand and make sense. You have a new follower. Thank you.
good work , params ...
I am using Wix and have been trying to add this to my website for the past 4 hours... completely new to code and no clue where to start. How would this be formatted for HTML? Thank you!
It's amazing!
Wow, very very clever.
Good job Ksenia.
Hmm, am I doing something wrong? Tested it on a website. As soon as I scroll down, the ink line stays more and more away from the cursor.
I see what you mean, Andi
Your issue is not about the animation itself but rather about getting correct pointer position.
pointer.xandpointer.yproperties should be calculated ** relative** to the<canvas>element.In the original demo,
<canvas>has a full-screen size, and<canvas>position is set tofixed(see CSS code). In this setup, we can track cursor position simply usinge.pageXande.pageYproperties (see event listeners in the JS code).But if
<canvas>position isn't fixed and there are other HTML elements above the animation, you need to take into account the top offset of<canvas>itselfThere're different ways to do so, for example
You can google "pointer position relative to element" to learn about the topic