Adjust the font color as the SVG Animation in the Background transforms

I have designed an intricate SVG animation for my background and paired it with text. For reference, please refer to this jsFiddle link.

HTML:

<div class="content">
    <!-- Background SVG -->
    <svg width="1500" height="800" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" class="background-svg">
        <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
        <g>
            <title>Background</title>
            <path fill="#fefefe" stroke="#000000" stroke-width="5" d=" m498.33967,-113.03246c99.6527,78.64871 -127.11402,258.15614 -190.68809,236.79926c-63.57406,-21.35688 -114.68809,-306.16174 -46.65269,-211.12362c68.0354,95.03812 137.68808,-104.32435 237.34078,-25.67564z" id="shap" stroke-opacity="0" fill-opacity="0.9" />
        </g>
    </svg>
    <!-- /Background SVG -->

    <div class="container">

        <!-- Intro -->
        <div id="intro">
            <p >Text</p>
            <h1 ><strong>Title Here</strong></h1>

        </div>
        <!-- /Intro -->


    </div>
                    </div>
                </pre>
        
                <p><strong>CSS</strong></p>
        
                <pre><code>.content {
        color: #fff;
        background-color: #f857a6;
        position: fixed;
        top: 0;
        height: 100%;
        width: 100%;
    }
    .background-svg {
        position: absolute;
        z-index: -4;
        width: 100%;
        height: 100%;
    }
    .background-svg path {
        -webkit-animation: svgAnimate 20s infinite alternate linear;
        animation: svgAnimate 20s infinite alternate linear;
    }
    @-webkit-keyframes svgAnimate {
    to {
            d: path("m276.33967,389.03246c130.6527,-65.35129 -20.11402,367.15614 -190.68809,236.79926c-170.57407,-130.35688 -161.68809,-159.16174 -46.65269,-211.12362c115.0354,-51.96188 106.68808,39.67565 237.34078,-25.67564z");
        }
    }
    @keyframes svgAnimate {
        to {
            d: path("m276.33967,389.03246c130.6527,-65.35129 -20.11402,367.15614 -190.68809,236.79926c-170.57407,-130.35688 -161.68809,-159.16174 -46.65269,-211.12362c115.0354,-51.96188 106.68808,39.67565 237.34078,-25.67564z");
        }
    }
        
    /*====================*/
        
        
    /* Intro Div */
        
    #intro {
        
        border-radius: 20px;
        padding: 60px;
        height: 500px;
        position: relative;
        
        margin-top: 7%;
    }
    .name {
        font-family: 'Raleway', sans-serif;
        font-weight: 900;
    }
        
    /*====================*/
    

I would like to modify the text color in sync with the animation's movements, reverting to the default color when it transitions out.

Can anyone assist me with this?

Thank you in advance

Update:

Resolved using another example: https://codepen.io/norhan22/pen/jwJvxw?editors=1100

Answer №1

Using the CSS property mix-blend-mode provides a solution. This property controls how an element blends its colors with the contents of its parent element.

An example would be setting:

mix-blend-mode: exclusion;

This will cause the text color to invert when it intersects with the moving blob. To prevent the pink background color from affecting the color, it should be moved to an element that is not the <svg> or its parent (<div class="content">). For this example, the background color has been moved to the <body> element.

The specified code will work in all modern browsers except IE. However, please note that the animation only functions properly in Chrome at the moment.

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

The function is missing a closing return statement and the return type does not specify 'undefined'

It seems like the function lacks an ending return statement and the return type does not include 'undefined'. In a recent refactoring of the async await function called getMarkets, I noticed that I had mistakenly set the return type as Promise: ...

Error: The variable "require" cannot be located

I'm having trouble loading the node_modules onto one of my webpages. Despite having npm and node.js installed, I keep getting a ReferenceError when trying to use the require() function to initialize Firebase on my website. ReferenceError: Can' ...

Does the parent container require a defined width?

I'm working with a parent div that contains three inner child divs. Here's the structure: <div style="width:900px;"> <div style="width:300px;">somedata</div> <div style="width:300px;">somedata</div> <div ...

What is the method for notifying the latitude within this Google Maps javascript code?

There's a specific line that triggers an alert showing "undefined". However, when I just alert results[0].geometry.location, it displays (41.321, 41.556). My goal is to alert this value and then convert it (as an integer) to my id_lat and id_longs... ...

Enhance your webpage by incorporating various icons and custom spacing using Font Awesome and CSS content

Utilizing Font Awesome icons can be done with the code snippet below: .icon-car { content: "\f1b9"; } Is there a way to include multiple icons (such as \f1b9 and \f1b8), separated by a non-breaking space? ...

Solution: "The Mongoose Model.find method consistently provides an empty result set."

Currently, I am utilizing mongoose in combination with next.js to interact with an existing collection. Despite the collection not being empty, the mongoose model.find() function consistently returns an empty array. Below is my model code: const mongoose ...

Is it possible to incorporate current cljs components into a React project?

https://www.reddit.com/r/Clojure/comments/4el0xi/how_to_use_an_existing_reactjs_component_with/ In the Reddit post linked above, there is a discussion on how to incorporate existing ReactJS components into a CLJS/Reagent project. However, my aim is slight ...

Troubleshooting problems with resizing images using CSS

I am experiencing an issue with resizing images that I have configured in the admin panel. .users-list>li img { border-radius: 50%; max-width: 100%;    height: auto;     width: 100px;     height: 100px; } When enlarged, the images l ...

HTML code to make navbar change color when clicked

Having some trouble with my very first website. I managed to put together a navigation bar at the top that is close to what I want (aside from the colors). The problem is, when I click on different links, I want the box to change color but it's stuck ...

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 ...

"Utilize Ajax to trigger a custom alert message once data is loaded and ready

Is it possible to customize the data object in order to show a JavaScript alert saying "The email address has already been registered!"? Currently, the servlet returns a boolean indicating whether the email is already in the database. $('#emailInput ...

The checkboxes seem to be malfunctioning following an ajax request

I've been attempting to utilize ajax to load data, but for some reason the checkboxes aren't functioning. Below is the HTML I'm trying to load via ajax: <div class="mt-checkbox-list" > <?php foreach($product_offerings as $row){ $c ...

Encountered a Server Error: Invalid hook call. Hooks are restricted to being called within the body of a function component specifically in _app.js

As someone new to React and Next JS, I am facing an issue with setting initial auth user data on the initial load from the __app.js file. Whenever I try to use dispatch, it throws an error saying "Invalid hook call". I understand that calling hooks in the ...

Install only the necessary components from React Material UI

Is it possible to selectively install specific components from React Material UI? Specifically interested in the Autocomplete component, which can be found at this link. ...

"Implement a style change to an element upon clicking outside of the specified element defined in an Angular directive

I've implemented SVG items that highlight their corresponding path when a user clicks or hovers over them. To achieve this, I am utilizing Directives to detect events such as onEnter, onLeave, and Click. The highlighting works smoothly when I hover ...

Exploring the benefits of refactoring jQuery promises in use cases

I've been thinking about how to optimize this pseudo-code: function foo() { if (condition) { return somethingReturningPromise().then(function (data) { doSomethingOnSuccess(data); return mainFunctionReturningPromise(); // he ...

Using this PHP function

I am facing an issue with a table that contains some information. I want to be able to click on a specific row (e.g. the second row) and display all the corresponding database information. However, I am unsure how to achieve this using the $this function ...

creating a gap between two links within a div element

I have a dilemma regarding the spacing between two hyperlinks within a div tag. Can anyone advise on how to create this space effectively? .btn-filter { background-color: #ffffff; font-size: 14px; outline: none; cursor: pointer; height: 40px ! ...

The unique format created by tinyMce is not being displayed

I am trying to customize the style format of my tinyMCE, but I am having trouble getting it to show up. Can anyone suggest what might be going wrong? Where should I place the button "Formats" so that I can choose a specific style? tinyMCE.init({ mod ...

How does JavaScript manage to be both non-blocking and asynchronous while also being single-threaded?

I'm struggling with understanding how Javascript can maintain a single-threaded nature while still being non-blocking on the client. My current mental model is akin to an assembly line: Imagine a single assembly line at the beginning of code execu ...