Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
DeltaFrog

AddEventListener on visible part of transparent png

Go to solution Solved by PointC,

Recommended Posts

Hi All,

 

Does anyone know how to target the visible part of a .png with a listener instead of its containing div?  I want the mouse over function to run when the mouse is over the visible part of the .png instead of the square div its in.  

 

I tried this path and it worked but the transparent part of the png still activates the listener.   Id also like to apply a glow to the PNG so I don't have to swap in another image.  Can GSAP do glows?  Thoughts?   :D

 

document.querySelector("#largeShipID > img").addEventListener('click', function(){

 

See the Pen QWaepXJ by deltafrogcraft (@deltafrogcraft) on CodePen

Link to comment
Share on other sites

  • Solution

You could drop it into an SVG and use a clip-path. (Pointer events will only register on the revealed area.) Then add a separate glow image. I'd do something like this:

 

See the Pen QWQLGqY by PointC (@PointC) on CodePen

 

Happy tweening.

:)

 

  • Like 4
Link to comment
Share on other sites

AMAZING!  Thanks Craig!

  • Like 1
Link to comment
Share on other sites

Happy to help. That was a fun one. :) 

 

Just FYI - I converted the .png files to .webp which resulted in a lot smaller file size. You don't have to do that, but this is an excellent place for quick conversions.

https://cloudconvert.com/

 

Happy tweening.

:)

 

  • Like 2
Link to comment
Share on other sites

I will start exporting .webp, thanks Craig!   :mrgreen:

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.
×