Animating the background color within the Angular 4 side menu

In my quest to create an interactive user interface, I am looking to add animation effects to the background of my active element within a side menu. Here is the HTML code snippet I currently have:

    <ul>
      <li>Dashboard</li>
      <li>Content Hub</li>
      <li>Users</li>
      <li>Sources</li>
      <li>Stories</li>
      <li (click)="toggleActive()" [ngClass]="[active ? 'active' : '']">Workshop</li>
      <li>Tags</li>
      <li>Reports</li>
      <li>Custom Categories</li>
    </ul>

As of now, this menu serves as a test case for the animation effect I'd like to achieve. When Workshop is clicked, I want the background color to smoothly slide in from the left to right and when it loses its active status, the background should slide out from right to left.

Regarding CSS styling, I initially considered adding transitions but I'm wondering how to specify the direction of the movement from left to right or vice versa. Below is the relevant CSS code:

li {
        width: 65%;
        margin-bottom: 20px;
        padding: 15px 0 15px 40px;
        cursor: pointer;
        background-color: transparent;
        transition: 1s all ease-in-out;

        &.active {
          background-color: #fff;
          transition: 1s all ease-in-out;
        }
      }

Answer №1

Is this what you're looking for?

Sample HTML:

<ul>
  <li>Home</li>
  <li>About Us</li>
  <li>Services</li>
  <li>Portfolio</li>
  <li>Blog</li>
  <li>Contact</li>
  <li class="current">FAQs</li>
  <li>Testimonials</li>
</ul>

Corresponding CSS:

   ul li {
  background: #fff;
  padding: 10px;
  border: 1px solid #eee;
  position: relative;
  z-index: 3;
  font-family: 'Arial', sans-serif;
  font-size: 14px;
}

ul li::before{
  content: "";
  position: absolute;
  width: 0;
  height: 100%;
  top: 0;
  left: 0;
  background: #5ca5f0;
  transition: .3s;
  z-index: -1;
  opacity: 0;
}

ul li.current::before{
  width: 100%;
  opacity: 1;
}

ul li.current{
  color: #fff;
}

http://jsfiddle.net/8Lmqka75/

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 'co.Number' function is not recognized as a valid function due to a

I'm attempting to perform string multiplication using Angular. <h5>{{Number(someString) * Number(someOtherString)}}</h5> Unfortunately, I encountered this error: ERROR TypeError: co.Number is not a function Is there a way to multiply ...

Problem with sequential promises

import { Observable } from 'rxjs/internal/Observable'; export function createHttpObservable(url: string) { console.log('Url is', url); return Observable.create(observer => { fetch(url) .then(response => { ...

The height of the iframe with the id 'iframe' is not functioning as expected

I am trying to set the iFrame's height to 80% and have an advertisement take up the remaining 20%. Code <!DOCTYPE html> <html lang="en"> <head> </head> <body> <iframe id="iframe" src="xxxxxx" style="border: ...

Uninitialized variables in Angular 4.0 causing Rxjs issues

Since the update to angular 4.0, I've been encountering errors with RxJs variables. While everything builds without any issues, when I try to load the page, I receive this error message: ERROR Error: Uncaught (in promise): TypeError: Cannot read pr ...

Trouble with z-index when attempting to stack forms on top of one another

Currently, I am working on creating a login page and signup page for my program. The goal is to stack them on top of each other with only one being displayed at a time. However, I am facing an issue where they are not stacking properly. I attempted using t ...

Positioning the horizontal menu and footer links to the right side of the page

Struggling to get my menu and footer links aligned all the way to the right of the page. Here's what it currently looks like http://prntscr.com/32snbr, and this is the desired alignment http://prntscr.com/32snrm I've shared the HTML code below, ...

``I am having difficulty with Bootstrap as it seems to be hiding my field or

I'm currently working on a webpage that uses Bootstrap. It has a form with a label and text input field. When I add the class="custom-control-input" to the input field, Bootstrap hides it. Can someone explain why? If I don't include the class, ...

The expected response from CSS3 animated images may not be fully realized

I've been working on this project with 4 images. While hovering over one image causes the others to change size as intended, I can't figure out why the ones on the left are not following the same pattern even though I have specified that they sho ...

Tips for avoiding Google Tag Manager from interfering with document.write() function

We have integrated Angular into our website, however, not all pages have been migrated to Angular yet. To handle this situation, we have implemented a hybrid approach: Each request is initially directed to Angular. Once the page is loaded, it checks if th ...

Accessing a function from a separate module in Angular 2

I am encountering an error message stating "has no exported member test" when trying to import test from ConfigAppProviderModule. Could there be a mistake in how I am writing the service with config in the module? import { NgModule ,InjectionToken,Injec ...

Bootstrap dropdown malfunction

I am having trouble with my dropdown menu. The browser is cutting off the blue box in the dropdown area. I'm not sure if I need to add some CSS or make changes to the Bootstrap code to fix this issue. I haven't made any unusual modifications, jus ...

Insert a new row into a table using tablesorter jQuery

Is it possible to add a row to a table built with the jQuery library "Tablesorter" by simply clicking on a button? I have tried this approach, but unfortunately, the new row does not inherit the CSS properties of Tablesorter. As a result, I am unable to se ...

The grid display's columns are hidden on smaller screen devices

I am working on a webpage with the following HTML structure: .main { display: grid; grid-template-columns: 1fr 2fr; } .main>div { height: 200px; } .main>div:first-child { border: solid 3px red; } .main>div:last-child { border: soli ...

Why is the media query not affecting this image?

<div class="col-lg-6" > <img src = "iphone6.png" id="dog-mobile" alt="phone"> </div> #dog-mobile{ height:600px; position: absolute; right: 25%; transform: rotate(25deg); } ...

Ways to eliminate a Collection of CSS2DObject from the environment

I have a dynamic msg_arr array of strings that I want to display visually, and I need to clear the existing errs Group of CSS2DObject from the scene before creating a new errors Group. The issue here is that although the new CSS2DObjects are added success ...

Designing my website to resize and adapt to different screen resolutions using CSS

As I navigate my first week of CSS, HTML, and PHP programming, I encountered a problem with text overlapping and causing issues on my site when scaled according to window size. I'm seeking clarity on what mistakes I may be making. Despite trying medi ...

What is the workaround for using DomSanitizer in a unit test when the component does not automatically inject it?

I have a basic component that does not utilize the DomSanitizer. Let's call it export class ExampleComponent { @Input() public safeHtml: SafeHtml | undefined; } How can I incorporate the DomSanitizer in a unit test? I have attempted to prov ...

Absolute positioned content causing unexpected spacing on top of relative positioned content

I've been experimenting with a fantastic technique by Chris Coyier for implementing full page video backgrounds with content scrolling over the video. However, I've encountered an issue where there's an unexpected gap to the right in Windows ...

What are the steps to turn off the rule .MuiInputBase-inputType-121 in Material UI TextField for email input field because of a display problem?

Here is a snippet of JSX code: import TextField from '@material-ui/core/TextField/TextField'; <Col xs={6}> <TextField pattern=".{3,}" name="fullName" ...

Attempting to make Navbar vanish as the page size decreases

I am a beginner in html and css and my instructor wants us to create a resume using bootstrap. Bootstrap is designed to provide interactive design that adjusts seamlessly across different devices. I am currently working on aligning elements and I would lik ...