Jump to content
Search Community

Objects interact with mouse move

Anas Ali Khan test
Moderator Tag

Recommended Posts

  • Anas Ali Khan changed the title to Objects interact with mouse move

Yeah definitely. Be aware though that is not a simple mouse enter/leave events since you need also the coordinates of the mouse pointer inside the element to morph the SVG in the way you want. Again not impossible but it has some complexities.

 

Happy Tweening!

Link to comment
Share on other sites

Absolutely, I appreciate the heads-up about the complexities involved. I'm keen to dive into this challenge, though. Do you have any recommended resources or examples that demonstrate similar effects with SVGs and mouse interactions? Specifically, I'd love to see how to accurately track mouse coordinates within an SVG element and use that data to morph the SVG shapes in real-time. Also, any tips on managing performance issues that might arise from such real-time graphics manipulation would be incredibly helpful. Thanks again for your guidance!

Link to comment
Share on other sites

Keep in mind that the mousemove event can be added to any DOM element:

https://developer.mozilla.org/en-US/docs/Web/API/Element/mousemove_event

 

Also take a look at the demos by @nico fonseca and @akapowl in this thread

 

As for the path manipulation you can play with the d attribute on an SVG path in order to create the bezier based on the mouse position:

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d

 

But be aware that is in no case a simple endeavor since you'll have to create the beziers by hand on the mousemove event and apply those to the d attribute in the path element.

 

Another option is to create animations using the MorphSVG Plugin and control them based on the mouse position:

https://gsap.com/docs/v3/Plugins/MorphSVGPlugin

 

Happy Tweening!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...