27
loading...
This website collects cookies to deliver better user experience
ref
for these elements so that we can access the DOM elements later on.cursor: none
is added to the universal selector *
because we want to hide the default cursor.pointer-events: none
so that this element doesn’t become a target of the pointer-events. MDN pointer-eventsposition: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 1;
is used so that later on we can hide and show our cursor based on mouseenter
and mouseleave
event. That’s why transition
is also used on the opacity
property.transform
is used so that we can increase and reduce the size of the dot and outline based on some mouse events (will soon get to know which one 😉).<Link />
component which can be reused for displaying the images.<Cursor />
component and pass the images. ref
to its container because we’ll be adding the mouse events to all those images.getImage
is a util function that I created in order to get the images based on the index value provided by the map function. You can find the function in the source code (not adding any image because it isn’t that important. Sorry getImage
function! 😥). jsconfig.json
. You can add this file at the root of your project and add the baseUrl
property inside compilerOptions
.[...Array(4).keys()]
code snippet Array(4)
will create an empty array of size 4.keys()
method returns a new Array Iterator object that contains the keys for each index in the array.[0, 1, 2, 3]
refs
to our Cursor component so that we can update the changes. window.innerWidth/2
because that’s mid of X-axis.toggleCursorVisibility — If the cursor is visible then we will change the opacity to 1 otherwise we will change it to 0.
toggleCursorSize — If the cursorEnlarged is true then we will decrease the size of the dot and increase the size of the outline. In case of a false, we will change it back to the original size.
requestAnimationFrame
function. In this function, we update the position of cursor outline with respect to the position of cursor dot.useEffect
(componentDidMount). At the time of unmounting, we should remove all the event listeners and also cancel the requestAnimationFrame using cancelAnimationFrame function.