Unable to recycle SASS @mixin: Repeating previous parameter value

I am attempting to give 3 circle icons a glowing effect using a Sass @mixin with Font Awesome icons.

_mixins.scss

@mixin textGlow($glowColor: 0){
    @keyframes glow{
        from {
            text-shadow: 0 0 1px $glowColor, 0 0 2px $glowColor, 0 0 3px $glowColor;
        }
        to {
            text-shadow: 0 0 3px lighten($glowColor, 5%), 0 0 4px lighten($glowColor, 15%), 0 0 5px lighten($glowColor, 30%);
        }
    }

    @-webkit-keyframes glow{
        from {
            text-shadow: 0 0 1px $glowColor, 0 0 2px $glowColor, 0 0 3px $glowColor;
        }
        to {
            text-shadow: 0 0 3px lighten($glowColor, 5%), 0 0 4px lighten($glowColor, 15%), 0 0 5px lighten($glowColor, 30%);
        }
    }

    -webkit-animation: glow 1s ease-in-out infinite alternate;
    -moz-animation: glow 1s ease-in-out infinite alternate;
    animation: glow 1s ease-in-out infinite alternate;
}

app.component.scss

@import '../styles/variables';
@import '../styles/mixins';

i.fa-circle.good{
  color: $my-green;
  @include textGlow($my-green);
}

i.fa-circle.bad{
  color: $my-red;
  @include textGlow($my-red);
}

_variables.scss

$my-green: #00BB9C;
$my-red: #FB4D62;

Even when passing in $my-red for the .bad class, there is still a red glow around the green icons.

https://i.sstatic.net/JtRUL.png

The last color parameter passed into the @mixin will cause all glows to have that same final color.

I have investigated tutorials on @mixin to understand my error, but I cannot pinpoint where I went wrong. I tried assigning to a local $local-color variable within the mixin without success.

Aren't mixins meant to allow reuse of CSS properties? Can someone please help me identify how I am misusing @mixin here? Or should I not be using @mixin in this scenario?

I have recreated an example on Stackblitz

Answer №1

The issue lies in the keyframe name that is being utilized. Making the following adjustment should resolve the problem.

mixins.scss

@mixin textGlow($name, $glowColor){
    @keyframes #{$name}{
        from {
            text-shadow: 0 0 1px $glowColor, 0 0 2px $glowColor, 0 0 3px $glowColor;
        }
        to {
            text-shadow: 0 0 3px lighten($glowColor, 5%), 0 0 4px lighten($glowColor, 15%), 0 0 5px lighten($glowColor, 30%);
        }
    }

    @-webkit-keyframes #{$name}{
        from {
            text-shadow: 0 0 1px $glowColor, 0 0 2px $glowColor, 0 0 3px $glowColor;
        }
        to {
            text-shadow: 0 0 3px lighten($glowColor, 5%), 0 0 4px lighten($glowColor, 15%), 0 0 5px lighten($glowColor, 30%);
        }
    }

    -webkit-animation: $name 1s ease-in-out infinite alternate;
    -moz-animation: $name 1s ease-in-out infinite alternate;
    animation: $name 1s ease-in-out infinite alternate;
}

app.component.scss

i.fa-circle.good{
  color: $my-green;
  @include textGlow('greenglow', $my-green);
}

i.fa-circle.bad{
  color: $my-red;
  @include textGlow('redglow', $my-red);
}

https://i.sstatic.net/ApW9K.png

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

How can the HTML email width be adjusted on Outlook 2016?

When I send out HTML emails, I encounter an issue where the content takes up the full width no matter what. I have tried adjusting the width of table, tr, td, div, and body elements, but it still persists. This problem occurs on Outlook 2016 across all W ...

Ways to retrieve the ID of the clicked element from the child up to the parent

I currently have a Parent component and a Child component. The Child component contains inner elements called notes, with "delete" being one of them. My goal is to have the Child component return an ID to the Parent component when the delete element is cl ...

Is it possible to convert ejs to jade?

I'm struggling with the conversion of this ejs code to jade: <h1>I’m planning on counting up to <%= counter %></h1> <p><% for(var i = 1 ; i <= counter ; i++) { %> <%= i %>... <% } %></ ...

Triggering Leaflet's Mouseout function during a MouseOver event

I am working on a leaflet map project where I am dynamically adding markers. One of my goals is to have the marker's popup appear not only when clicked, but also when the user hovers over it. This is the code snippet I have been using: function mak ...

Shadowing jQuery variables involves declaring a new variable with the

There seems to be an unusual pattern used in jQuery: var jQuery = (function() { // This local copy of jQuery is defined within a closure var jQuery = function( selector, context ) { ... return jQuery; })(); Why was this approach chosen? Instead of exp ...

Struggling to align my image and text next to each other in three different sections using Bootstrap

Having difficulty aligning my images to the left of each block of text, they keep appearing underneath. I am utilizing col-md-4 for three sets of text and image. .container { float: left; display: block; } <div class="container"> <!--Row ...

modified a file using express framework

I am attempting to utilize mongoDB in order to update the status of an existing document. Despite my backend successfully receiving the routes, the mongoDB update process is not functioning as expected. router.post('/orders_drivers', function (r ...

Struggling to customize checkbox design using HTML and CSS

Why am I unable to style HTML checkboxes with CSS? No matter what I try, the appearance of the checkboxes remains unchanged: Here is the HTML code: <input type="checkbox" id="checkbox-1-1" class="regular-checkbox" /> <nput type="checkbox" id ...

Error in inferring argument types for a generic interface function in Typescript

Unique interface export interface DataService { getByTypeId<T extends number | string>(id: T): Promise<SomeType>; } Additionally, the implementation export class BService implements DataService { async getByTypeId(id: number): Promise&l ...

Creating a CSS style within a Django model field

If I have the following code snippet: In models.py file: from django.db import models from django.contrib.auth.models import User class MyClass(models.Model): username = models.ForeignKey(User, blank=True, null=True) my_field = models.CharField(ma ...

I am looking to display multiple divs sequentially on a webpage using JavaScript

Looking to display a rotating set of alerts or news on my website. The goal is to show each news item for a certain number of seconds before moving on to the next one in line. However, I'm new to javascript and need help creating a code that will cont ...

What is preventing this jQuery from altering the opacity?

Currently, I have a piece of code that is intended to change the opacity of a div element from 0 to 1 as soon as the user initiates scrolling on the body. However, it appears to be malfunctioning for reasons unknown. $("bod").load(function(){ document ...

The data type 'string | null | undefined' cannot be assigned to the data type 'string | undefined'

In my Angular application using Typescript, I have the following setup: userId?: number; token?: string; constructor(private route: ActivatedRoute) { this.route.queryParamMap.subscribe( (value: ParamMap) => { this.userId = val ...

Guide on how to incorporate Angular with Ionic 2

We are set to kick off our brand new mobile app using the cordova+ ionic2 framework. While it's reported that angular2 is currently in beta and is expected for production release in 2 months, our team believes we can still begin the project. However, ...

Looking to display an SVG icon and text side by side in HTML/CSS/Bootstrap?

I'm having trouble displaying an inline SVG image/icon and text on the same line. Here's the code snippet: .row.justify-content-left.icon1 { padding-left: 260px; padding-top: 36px; } <div class="row justify-content-left icon1"> <d ...

Setting the initial date value for an Angular Material md-datepicker to a specific date

When using Angular Material md-datepicker, by default the system's current date is set as today's date and highlighted in the calendar. However, I am looking for a way to manually set any given date as today's date instead. Please see this i ...

Learning how to utilize getDerivedStateFromProps over componentWillReceiveProps in React

To address a deprecated error, I am looking to update my code from using componentWillReceiveProps to getDerivedStateFromProps. The component is being passed a date prop, and whenever this date changes, the getList function needs to be run with the new dat ...

Customizing Angular Components: A guide to modifying a component template without creating a new component

I am searching for a solution to utilize my components by replacing the standard templates with custom ones, while still maintaining AOT compatibility. Instead of writing a new component to replace the original template, I want to establish a convention-o ...

Prevent Border Around Images within a Child DIV

Currently, I am in the process of designing a Tumblr theme and facing the challenge of making my pages visually appealing. One particular issue that is causing me trouble is my desire to have images on individual pages bordered in green with a maximum wid ...

Creating a basic dynamic slideshow/timelapse from scratch

I have a directory containing webcam images that are saved periodically. I am interested in creating a slideshow using these images for a time-lapse effect, without any transition effects or background music. The slideshow should be dynamic so I can use ...