What steps should I take to ensure that elements beneath a div are made visible?

I've been working on a unique project to create a website with "hidden text" elements.

One of the cool features I've developed is a circular div that follows my mouse cursor and flips all text below it using background-filter in both CSS and Javascript:

let circle = document.getElementById('circle');

const onMouseMove = (e) => {
    circle.style.left = e.pageX + 'px';
    circle.style.top = e.pageY + 'px';
}
  
document.addEventListener('mousemove', onMouseMove);

The styling for the #circle element looks like this:

#circle {
    position: absolute;
    transform: translate(-50%,-50%);
    height: 80px;
    width: 80px;
    border-radius: 50%;
    box-shadow: 0px 0px 40px 10px white;
    pointer-events: none;
    backdrop-filter: invert(100%); 
    z-index: 100;
}

I've attempted to adjust the text opacity to 5% and then utilize backdrop-filter: opacity(100%) but unfortunately, it didn't deliver the desired result. How should I proceed to make this work? I'm open to exploring different libraries and following tutorials. Accessibility isn't a concern right now since this is purely an experimental endeavor.

Answer №1

I successfully achieved the desired effect using the CSS clip-path property:

const element = document.getElementById("element");

const onMouseMove = (e) => {
  element.style.clipPath =
    `circle(40px at ${e.pageX}px ${e.pageY}px)`;
}

document.addEventListener('mousemove', onMouseMove);
<div id="element">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis arcu diam, mattis vel mi sit amet, consequat dapibus sapien. Integer blandit et justo sit amet pharetra. Quisque facilisis placerat aliquet. Proin at dictum sapien. Proin ac urna quis leo
    vehicula semper. Pellentesque condimentum scelerisque aliquam. Nunc vitae pellentesque tortor.</p>
</div>


<div id="shape"></div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Asynchronous requests in Node.js within an Array.forEach loop not finishing execution prior to writing a JSON file

I have developed a web scraping Node.js application that extracts job description text from multiple URLs. Currently, I am working with an array of job objects called jobObj. The code iterates through each URL, sends a request for HTML content, uses the Ch ...

deactivate a vessel, causing all of its contents to be rendered inactive

Hi there, I am in search of a container that has the ability to disable all elements within it, not just inputs but also images and other elements without the disabled property. I do not want to hide the container, but rather disable it. Do you know if suc ...

Jpicker is renowned for its transparency feature

I am currently using the Jpicker jpicker-1.1.6.js script which can be found at Below is a snippet of my code: <script type="text/javascript"> $(function() { $.fn.jPicker.defaults.images.clientPath='/img'; var ...

What is the reason for Sublime 3 highlighting all ID selectors in CSS with yellow?

A single image can convey a multitude of meanings: Sublime 3 (build3083) is highlighting the #something selector as a yellow warning, while .classtag appears to be fine. I don't usually work with CSS, so this issue is quite bothersome. How can I r ...

The variable in the HTML input value is not fully visible when filling out the HTML form

I am working with a Python Flask code where I have passed a dictionary to an HTML form. The table in the form correctly displays both keys and values, but when trying to populate a form field with the value from the dictionary, only the first word is displ ...

After the decimal point, there are two digits

My input field is disabled, where the result should be displayed as a product of "Quantity" and "Price" columns ("Quantity" * "Price" = "Total"). However, I am facing an issue where the result often displays more than 2 digits (for example: 3 * 2.93), desp ...

Understanding the flattening process of arrays using JavaScript - Detailed explanation required

Currently, I am immersed in the captivating world of Eloquent JavaScript. However, I have hit a roadblock with one of the exercises that involves flattening a multi-dimensional array. Despite my best efforts, I have been unable to crack the code. After f ...

Express & React: Be cautious of client checksum and style while server-side rendering

Recently delving into the world of React server side rendering, I'm currently working on a small demo utilizing technologies such as React, Redux, React Router, and Material UI. The main issue I'm encountering is the following warning. I am uncer ...

Cannot use MaterialUI Textfield/Input on iPhone devices

Recently, I encountered an issue with iPhone users being unable to type in Textfield or Input components in apps developed using MaterialUI, even when the value and setValue were properly configured. To solve this problem for each component individually, ...

Exploring the React component life cycle: Understanding the distinction between render and return, and what happens post-return

This question pertains to the concepts surrounding react component life cycles. Below is an example code snippet provided as a general reference. const Modal = ({ className, variant, width, withCloseIcon, isOpen: propsIsOpen, onClose: tellParen ...

Why are child elements missing from my BeautifulSoup <ul> list? Is it a parser issue?

My code snippet is as follows: import bs4 as bs from urllib.request import urlopen page = urlopen("https://www.netimoveis.com/locacao/minas-gerais/belo-horizonte/bairros/santo-antonio/apartamento/#1/").read() soup = bs.BeautifulSoup(page, "lxml") div_l ...

AngularJS ngAnimate triggering prematurely

In the current setup, p2 animates in while p1 is still animating out. After that, p1 disappears and p2 glitches up the page. The desired effect is for 1 to fade out and then have 2 fade in. html: <nav> <a ng-click="changeView('p1' ...

Calculating the sha1 hash of large files using JavaScript in the browser without causing excessive memory usage

Is there a method to calculate the hash of large files in JavaScript without needing to load the entire file in a FileReader? Specifically, I'm interested in finding out if it's possible to stream a file and calculate its sha1 hash in JavaScript. ...

Darkening the background of HTML and CSS text to black

I'm having trouble removing the black background from the navigation. It doesn't appear to be styled in black when I inspect each element individually. Here is an image showing the issue: https://i.stack.imgur.com/gvbn8.png @charset "UTF-8"; ...

Stop vertical scrolling in a designated div container

I am dealing with a div that is overflowing, but the horizontal scroll bar is not visible. How can I prevent actual scrolling on the div when the user attempts to scroll using the mouse or arrow keys? Below is the code for this div and a snapshot <!- ...

Exploring the World of Google API JSON Parsing Using jQuery

I'm trying to retrieve Google search results using the Google Ajax API and then display them in a DIV element. Google presents its results in JSON format, but unfortunately, I am unsure how to handle it. I have searched extensively but have not foun ...

From Python Plotly to JavaScript Plotly - Leveraging the Power of

My primary goal is to avoid using JavaScript and instead focus on analytics. Is it possible for me to create Plotly graphs in Python (for example, in Jupyter notebooks) and then utilize the write_html function to seamlessly integrate them into fully deve ...

Performing a function multiple times by clicking the mouse

I have a function called week(), which provides me with the current first (startDate) and last (endDate) day of the week along with the week number. Additionally, there are two other functions, namely weekPlus() and weekMinus(), containing variables that i ...

Internet Explorer 11 has a problem with excessive shrinking of flex items

I have a flexbox setup with a left and right section, each of equal width. The left side displays an image and the right side contains text. While this layout works fine in Google Chrome, it does not wrap properly in Internet Explorer 11 when the width is ...

Accessing Cognito using ReactJS and fetching data with specific parameters

I'm currently attempting to retrieve the email of the user who is logged in and use it within my fetch() call. I have successfully obtained the email using getfirstapi() and used it in my form, but I am encountering issues when trying to pass it into ...