Jump to content
GreenSock

amit95

Changing the opacity of element that is in cursors area

Recommended Posts

I'm trying to go for an effect where an image has an opacity of less than 1. Then, when my custom cursor hovers over the image, that part of the image (that is visible via the custom cursor, as it has a transparent background), becomes fully visible. 

 

In addition to this, when the mouse enters and exists the card, it has a very jaggy entry and the on exit it almost blinks. I have the transitional conditions in the CSS, but it doesn't work as smoothly as you would expect. Is this a JS issue?

 

See the Pen MWGXMVP by amit_rai95 (@amit_rai95) on CodePen

Link to comment
Share on other sites

Hi,

 

The best options I can think of is using another image on top of the one that is visible and add a clip-path to it and use the same approach but with SVG.

 

I made some adjustments to your codepen and removed the CSS transition that you had on the cursor element because it was causing further issues because you had both GSAP and CSS fighting for control over the transforms of the cursor.

 

Here is a live example

See the Pen BaxPzvw by GreenSock (@GreenSock) on CodePen

 

Big shout out to @Cassie and @PointC who provided inspiration for something I had no idea it was possible until an hour ago. Check these threads to see the magic they worked:

Happy Tweening!

Link to comment
Share on other sites

Hi @Rodrigo,

 

Appreciate the demo, the effect is what I'm after. However, when their are multiple cards present, the mask also reveals that area on another card.

 

See demo below. I assume this is because of the if (overImage) {} conditional statement is not targeting that specific .card__image-mask element / a scoping issue?

 

Additionally, when you hover over the card initially, and then scroll down or up, the cursor and circle that is opacity that is completely visible is off?

 

See the Pen MWGXMVP by amit_rai95 (@amit_rai95) on CodePen

Link to comment
Share on other sites

We don't normally provide full custom solutions like this, but I was curious and decided it might help you and others if I showed this approach:

 

See the Pen zYjLmjE?editors=0010 by GreenSock (@GreenSock) on CodePen

 

I made the following enhancements: 

  1. Added motion to the cursor so that it's nicely eased into place. You can easily control how long that takes (the lag) by changing the duration in the quickTo() methods.
  2. I switched to animating transforms rather than top/left because it'll perform better. The top/left properties affect layout, so the browser has to do more work. Transforms are cheap layout-wise. 
  3. Set up a loop so that it properly handles each element that has that class applied to it.  
  4. Added a "scroll" event handler that adjusts the offsets in case the user scrolls while hovered over an image. 

Does that help? 

  • Like 1
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.
×