Ways to modify the color of text when it exceeds an element's boundaries

I'm trying to figure out how to change the text color when it hovers over a black circle HTML element that is fixed to the window. I've attempted using mix-blend-mode: difference;, but I can't seem to get it to work. Ideally, I want the text to appear white instead of black when it's positioned over the black circle.

Here is the demo code snippet where I am working on implementing this:

$(window).scroll(function() {

  var scroll = $(window).scrollTop();
  
  $(".background_image").css("transform", "rotate(" + scroll + "deg)")

  if($(window).scrollTop() + $(window).height() == $(document).height()) {
    $('.content').clone().appendTo('.content_wrapper');
   }
});
body {
  background: white;
  color: #323232;
  font-weight: 300;
  height: 100vh;
  margin: 0;
  display: flex;
  font-family: Helvetica neue, roboto;
}

.background_image {
  position: fixed;
  height: 100%;
  display: flex;
  justify-content: center;
  width: 100%;
  align-items: center;
  z-index: -1;
  mix-blend-mode: difference;
}

.background_image img {
  width: 300px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="background_image">
<svg style="position: absolute;" height="350" width="350">
  <circle cx="175" cy="175" r="150" stroke="black" stroke-width="50" fill-opacity="0"/> 
</svg>
<svg style="position:absolute;left: 47%" height="350" width="350">
    <circle cy="25" cx="25" style="display:flex;align-self:center" r="15" fill="white"/>
</svg>
</div>

<div class="content_wrapper">
  <div class="content">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p><h1>
Why do we use it?</h1><p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p><h2>
Where does it come from?</h2><p>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</p><p>
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
</p><h2>
Where can I get some?</h2><p>
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
  </p></div>
</div>

Answer №1

To make mix-blend-mode effective, it is necessary to use contrasting colors (e.g., white/black rather than black/black).

An alternative approach involves utilizing gradients, although there may be some issues in Firefox due to the interplay between text coloration and a fixed background:

$(window).scroll(function() {

  var scroll = $(window).scrollTop();

  $(".background_image").css("transform", "rotate(" + scroll + "deg)")

  if($(window).scrollTop() + $(window).height() == $(document).height()) {
    $('.content').clone().appendTo('.content_wrapper');
   }
});
body {
  font-weight: 300;
  height: 100vh;
  margin: 0;
  font-family: Helvetica neue, roboto;
}

.background_image{
  position: fixed;
  top:0;
  left:0;
  right:0;
  bottom:0;
  margin:auto;
  width: 350px;
  height: 350px;
  z-index: 1;
  mix-blend-mode:difference;
  background:
    radial-gradient(circle 20px at 50% 25px,#fff 97%,transparent 100%),
    radial-gradient(farthest-side,
      transparent calc(99% - 50px),
      black calc(100% - 50px) 100%);
  border-radius:50%;
  box-sizing:border-box;
}
.content_wrapper {
  color:transparent;
  background:
    radial-gradient(circle 175px,
       #000 calc(100% - 50px),
       #fff calc(100% - 50px) 100%,
       #000) 
       fixed;
  -webkit-background-clip:text;
          background-clip:text;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="background_image"></div>
<div class="content_wrapper">
  <div class="content">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p><h1>
Why do we use it?</h1><p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here...
</p>
<h2>
Where does it come from?</h2><p>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up o...
...
  generated Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
  </p></div>
</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

Identifying the language of characters written in English, Vietnamese, or Myanmar

My website is designed to support three languages - English, Vietnamese, and Myanmar. Users can submit content in any of these languages, and their submissions are stored in the database. When the content is displayed, I need to determine the language in w ...

Discover identical JSON elements in 2 JSON arrays using JavaScript and add CSS styles to the corresponding items within a UL list

In order to manipulate JSON data using JavaScript, I am required to create an HTML UL list of tags based on a JSON array of Tag items. Furthermore, there is a second set of Tags in another JSON data-set that needs to be compared with the first Tag JSON da ...

A line that shines brightest in its center, dimming slightly towards both ends

Recently, I stumbled upon some 80's retro design elements that featured glowing effects, such as this one: https://i.sstatic.net/aaJPR.png Would it be possible to recreate this glowing effect using just CSS? I'm thinking of creating a line with ...

What steps should I follow to utilize my spotify api token effectively?

Currently, I am working on developing a random playlist generator using the Spotify API. However, when I retrieve information from their server, I receive a 401 error code. I have managed to obtain an access token by following a tutorial. My main concern ...

Modifying the Vue.js Vue3-slider component for custom color schemes

Currently, I am using the vue-slider component and would like to customize the color of the slider itself. The specific class that needs to be styled is "vue-slider-dot-tooltip-inner". Below is a screenshot displaying the original CSS styling for vue-slid ...

Issues encountered while trying to implement HTML text within span tags

In my code snippet, I am using a span element: <span> {textToRender} </span> The purpose of this code is to render HTML text (as a string) within a span element. some text <br/> some text <br/> some text <ol>text However, wh ...

Populate a MySql database with 2 input values

I am facing an issue with inserting values into MySql from a table. When trying to insert two values, only one gets stored in the database and the other remains empty. Here is the structure of my MySql table: https://i.sstatic.net/yWLbO.png Below is the ...

Enhance the <div> with interactive content through dynamic updates on click within the same element

I am currently developing an Editor-Menu for a website administration. When I open admin.php, the Editor-Menu should be loaded into the #ausgabe div using the code $('#ausgabe').load('./admin-ajax/ajax2.php'). This functionality is work ...

Discovering the selected href URL using JQuery or JavaScript

How can I detect the clicked href URL using JQuery when no ID is being used? For example, if I have a list of links where some redirect to new pages and others call javascript functions to expand a div. What approach should be taken in JQuery/Javascript ...

Steps for adding a table at the bottom of your content

After hours of searching, I am still struggling to find a solution for my problem. My goal is to have the menu2.html appear at the bottom of the page, after the end of the content. I've tried various options like setting positions and using CSS styles ...

What is the best way to toggle an element's visibility using the select tag?

Let me break down the issue for you. In my HTML code, I have a select element that looks like this: <select id="seasons" multiple="multiple"> <option value="s01">Season 1</option> <option value="s02">Season 2</option> ...

having difficulty selecting a list item within the <nav> and <ul> tags using Selenium WebDriver

Within the nav tag, there is a list of elements. The goal is to click on the first element in the list. Below is the given HTML: <aside id="left-panel" style="overflow: visible;"> <div id="selectedBrand" class="custum-brand-info login-info"> ...

Extracting information from a website with C#

Hey everyone, I am looking to extract specific table data from a webpage instead of retrieving all the information. For instance, take a look at the URL provided below. There are multiple tables on the webpage. Can someone please provide me with a soluti ...

Tips on personalizing buttons within Telerik form or Kendo form

Having recently started working with Telerik UI, I am struggling to customize a Kendo form in ASP.NET Razor Pages. Specifically, I am trying to rename a button but cannot locate the button field within the code. Despite following the guidelines provided in ...

What is the best way to receive several responses from a PHP file using AJAX?

My PHP file is handling 2 operations: 1. Submitting data from a form into a database table, and 2. Sending an email. I am looking to display status messages through ajax. For instance, showing "First operation done, please wait for the second" and then di ...

Center the image and align the floated texts on each side horizontally

I've recently started learning about HTML and CSS, but I'm having trouble grasping one concept. My goal is to align two floating <p> elements on either side of a centered <img>. Here's an example of what I'm trying to achiev ...

Preventing page reload by using event.preventDefault() does not work with Ajax Form

I've been working on a code snippet to submit a form using Ajax without any page reloads: $( document ).on('submit', '.login_form', function( event ){ event.preventDefault(); var $this = $(this); $.ajax({ data: ...

Avoid triggering several ajax requests when the enter key is pressed

I've been using a PHP chat plugin and encountered an issue with it. The problem arises when the message is sent through a button press, as the plugin works perfectly fine in this case. However, when set to send messages on pressing "enter," it trigger ...

What could be causing my Jquery fade effect to not function properly?

I'm new to incorporating Jquery into my website and I'm facing an issue with getting the first row of pictures to fade in (upwards) when scrolling. Despite my efforts, they are not behaving as expected. Any guidance on how to resolve this? HTML: ...

In Google Chrome, the edges of hexagons appear jagged and not smooth

I have encountered an issue in Chrome where I created a hexagon group using HTML and CSS. While it displays fine in Firefox, the edges of the hexagons appear distorted in Chrome. Here are my code snippets: HTML <div class="col-sm-12 margin-left-100" i ...