The transition effect for the box shadow is being altered to modify the dimensions

--- UPDATE 2 ----

Here is a different example video showcasing the bizarre behavior of my react application. I am struggling to identify the root cause of this issue.

See the issue in action


I have a div with the class name side-btn

It contains an animation that is not functioning as expected. The animation is a simple box shadow transition:

.side-btn {
  height: 100px;
  width: 100px;
  background-color: white;
  box-shadow: 0 0 0 0 black;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 black;
  }
  70% {
      box-shadow: 0 0 10px 20px black;
  }
  100% {
      box-shadow: 0 0 0 0 black;
  }
}


<div class="side-btn"></div>

I referenced this pulse animation

In the provided code snippet, the animation behaves as intended. However, when implemented within my reactJS application using the same CSS styling, the behavior is completely different. The box simply expands and contracts without the desired pulse effect. Troubleshooting this bug has proven to be challenging.

function Sidebar(props) {
  return (
    <nav className = {"sidebar" + (props.active ? "" : " hidden")}>
      <div class="side-btn"></div>
    </nav>
  )
}

Upon inspection, it appears that the side button div is only changing size without pulsating as expected. Debugging this issue has been difficult.

-- UPDATE:

I have created a sandbox environment and used overflow's code snippets, which worked properly. However, once integrated into my react app, the undesired result persists. I have recorded a short clip for clarification. The exact cause of this discrepancy eludes me.

The only additional code difference is wrapping the side-btn within a 'sidebar' container, which centers it and offsets it slightly offscreen.

.sidebar {
  position: fixed;
  top:50vh;
  left:-35px;
} 

https://i.sstatic.net/CoKW8.jpg

Answer №1

To achieve the fading effect, it is important to specify the alpha value of the shadow color.

Instead of simply using black, consider using rgba(0,0,0,1) and rgba(0,0,0,0):

.side-btn {
  height: 100px;
  width: 100px;
  background-colour: white;
  box-shadow: 0 0 0 0 black;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(0,0,0,1);
  }
  70% {
      box-shadow: 0 0 10px 20px rgba(0,0,0,0);
  }
  100% {
      box-shadow: 0 0 0 0 rgba(0,0,0,0);
  }
  
}
<div class="side-btn"></div>

Answer №2

The change here is not in the box size but in the box shadow itself. On closer inspection, you will notice that the size of the div remains constant, only the shadow expands and contracts. The previous example had a high blur and spread area (with blur being relatively low), making it appear like a border rather than a box shadow. To clarify this, run the snippet below which is similar to the one provided:

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
}

.button {
  height: 100px;
  width: 100px;
  background-color: white;
  box-shadow: 0 0 0 rgba(0,0,0,1);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(0,0,0,0.7);
  }
  70% {
      box-shadow: 0 0 0 10px rgba(0,0,0,0);
  }
  100% {
      box-shadow: 0 0 0 0 rgba(0,0,0,0);
  }
}
<div class="wrapper">
  <div class="button"></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

ng2-table ways to customize the appearance of a particular row

Hey there, I'm currently new to Angular 2 and working with ng2-table. I've successfully added a table like the one shown here to my website. Now, I'm trying to figure out how to add color to specific rows within the table. Following the ste ...

Troubleshooting issues with loading scripts in a scrapy (python) web scraper for a react/typescript application

I've been facing challenges with web scraping a specific webpage (beachvolleyball.nrw). In the past couple of days, I've experimented with various libraries but have struggled to get the script-tags to load properly. Although using the developer ...

Exploring the power of directives in AngularJS for dynamically manipulating the

Using angular directives, I am attempting to dynamically replace a portion of HTML within a portlet on a webpage. The portlet contains two embedded sections. The top section includes a heading obtained from a separate backend service. <div class="head ...

What is the purpose of using a tag within a Next.js Link component?

Exploring the wonders of NextJs, I can't help but question why the a tag is necessary when creating a link. In the tutorial provided, we see this example: <Link href="/"><a>Back to home</a></Link> However, the link s ...

Expanding SVG Button Overlay in ChakraUI

I am trying to design a uniquely shaped button that sits on top of an image, but I am encountering some challenges with the scaling of the button mask. Both the image and masks were created at the same base dimensions for easy alignment at 0,0. Here is a ...

Is my component method not being accurately simulated by Jest and Enzyme?

Incorporating the "onKeyPress" event in my input, I aim to update a specific state when the "enter" key is pressed. This functionality involves appending the new input value to the existing languages array in the state. Although the functionality operates ...

Why does the Google Tag Manager noscript tag show up as a string when using react-gtm-module?

Implementing Google Tag Manager Tags in a React/Next.js app hosted on Netlify, I used the react-gtm-module. While the gtm script tag in the head section works perfectly, the noscript tag in the body is displaying an iframe as a string: <body> < ...

What can be done to prevent divs from overlapping? They display properly on a computer browser, but not on mobile devices like phones or tablets

Recently, I took on the task of creating an eBay template for someone. With some assistance and a bit of trial and error, I managed to get it working, albeit with what I like to call "not-so-great" code. However, there is one issue that arises when viewing ...

The function setState() is not performing as expected within the useEffect() hook

After retrieving data from my Mongo database, it's returned as an object within the useEffect hook function, specifically in the response. I then initialize a state called myorders with the intention of setting its value to the data fetched from the A ...

Guide on creating a server-side middleware in Next.js

In my upcoming nextjs project, which is a monorepo with both frontend and backend components, I am in need of a middleware to intercept requests. This middleware will handle tasks such as authentication and other necessary controls for every API call. Alth ...

Is there a way to retrieve the text value of an input using just function components in React?

import Layout from "components/Layout" import { useState } from "react"; export async function getServerSideProps(context) { const res = await fetch(`${process.env.NEXT_API_URL}/kana-terms/all`) const data = await res.json() ...

Having trouble aligning text and images in React with Material-UI?

I am currently working on designing my portfolio website using reactJs and material-ui. I am facing an issue with aligning the image with text and also a problem with non-responsive text. Essentially, I am trying to achieve text on the left side and image ...

The function document.getElementById is unable to select multiple elements simultaneously

I've been tackling a loading issue. I have a visible div, #loading, and multiple hidden divs, #message. I also have a JavaScript function. function loading() { setTimeout(function() { document.getElementById("loading").style.display = " ...

Troubleshooting: Unable to fetch CSS file in Node.js Express framework

I'm trying to access my .html file with localhost using node.js, but I'm facing an issue with loading the CSS that is included in the file. I am using the express framework for this purpose. Code: var express = require('express'); var ...

Customize the color of the horizontal line in React using dynamic properties

Is there a way to customize the color of an <hr /> element in a React application? If we were to use a functional component to accomplish this, how would we go about it? ...

I am facing an issue with my getServerSideProps function being undefined in my Next.js application, despite using a class component. Can anyone help me troub

Hey there, I'm currently facing an issue with retrieving props using getServerSideProps. I've tried various solutions but haven't been able to make it display properly. Below is the code snippet: import React, { Component } from 'react& ...

Steps for adding a background image in ASP.NET MVC4

I recently removed the reference to the master page from the head section @{ Layout = null } After making changes in my CSS: html { background-image:url('Images\BGP.jpg'); } However, I didn't see any changes. Any suggesti ...

Searching for text within an HTML document using Selenium in Python can be easily achieved by using the appropriate methods and

Is there a way to find and retrieve specific texts within an HTML file using Selenium in Python, especially if the text is not enclosed within an element? <div class="datagrid row"> ==$0 <h2 class="bottom-border block">Accepted Shipment</h ...

Allow one child to be visible even if the parent container has hidden overflow (or a different setting)

Is there a way to achieve the same look as shown in this example, but without repeating the border-radius code for the div.left in the CSS? It feels redundant and I suspect my approach may not be optimal. If you have any suggestions on how to accomplish t ...

React window resizing actionsWould you like some more information on this

I am attempting to create a resize function that will retrieve the window width and dynamically display it using react. Here is my current code: class Welcome extends React.Component { constructor() { super(); this.state = { ...