Day # 20: Flashlight



As frontend developers we often need to handle the cursor. Depending on its position, we may want to add certain functionalities to our websites. With that in mind, I decided to make this website that deals with the way the cursor moves throughout the website with an interesting consequence: the cursor acts as a flashlight in the middle of a scary forest…

The HTML is rather simple, since it only consists of having the picture of the scary forest on the background and one div that corresponds to the flashlight element.

For that flashlight element we need to select its position, both in the x and y axis, and then we need to add a circular background to it, to mimic the effect of a flashlight:

background: radial-gradient(

        circle 15em at var(--Xpos) var(--Ypos),

        rgba(0,0,0,0),

        rgba(0,0,0,1)

    );


Then, in Javascript we need to assign the values of those CSS properties, depending on where the cursor is located:


    flashlight.style.setProperty("--Xpos", mouseX + "px")

    flashlight.style.setProperty("--Ypos", mouseY + "px")

 

Comments

Popular posts from this blog

Day # 19: Checkbox animation

Day # 12: Typewriter Effect

Day # 53: Icon text