Smoothly transition the background hue of the moving <h2> element

Check out this plunker demonstrating the issue

This plnkr showcases a login interface with a sliding div that appears when clicked. Clicking on 'Down' will smoothly transition it back down.

The issue lies in my <h2> tag, which also changes its background-color causing it to flash white immediately when clicking 'Down'.

Here is my code:

HTML

<div class="login-container">
    <div [class]="sliderToggled ? 'slider opened' : 'slider closed'">
      <h2 *ngIf="!sliderToggled" class="login-title" (click)="toggleSlider()">Login</h2>
      <h2 *ngIf="sliderToggled" class="login-title active" (click)="toggleSlider()">Down</h2>

      <button class="button" (click)="login()" ion-button block>Log in</button>
    </div>
  </div>

TypeScript (only for toggling styles, but included for reference)

export class AppComponent {

  sliderToggled:boolean = false;
  constructor(){
    console.log('Ok');
    this.sliderToggled = false;
  }

  toggleSlider() {
    this.sliderToggled = this.sliderToggled ? false : true;
  }
}

CSS (refer to what I tried @ h2{})

body{
  background-color: #a13b4a;
}

h2{
    -webkit-transition: background .5s linear;
    -moz-transition: background .5s linear;
    -ms-transition: background .5s linear;
    transition: background .5s linear;
}

.login-title {
    height: 20%;
    background-color: white;
    width: 100%;
    color: #a13b4a;
    text-align: center;
}
.login-title.active {
    height: 20%;
    width: 100%;
    background-color: #a13b4a;
    color: white;
}

.login-container {
    position: fixed;
    left: 0px;
    bottom: 0px;
    height: 60%; 
    width: 100%;
}

.slider {
    overflow-y: scroll;
    height:100%;

    -webkit-transition:-webkit-transform .5s ease;
       -moz-transition:   -moz-transform .5s ease;
        -ms-transition:    -ms-transform .5s ease;
         -o-transition:     -o-transform .5s ease;
            transition:        transform .5s ease;
}

.slider.opened { 
    background-color: #a13b4a;
    -webkit-transform: translate(0, 0%);
       -moz-transform: translate(0, 0%);
        -ms-transform: translate(0, 0%);
         -o-transform: translate(0, 0%);
            transform: translate(0, 0%);
}
.slider.closed { 
    -webkit-transform: translate(0, 80%);
       -moz-transform: translate(0, 80%);
        -ms-transform: translate(0, 80%);
         -o-transform: translate(0, 80%);
            transform: translate(0, 80%);
}

I want the <h2> tag to smoothly transition alongside the slider, fading to white once the slider transition is complete.

Answer №1

It appears that the method you are using in Angular involves removing and reinserting the h2 element instead of simply toggling the active class on/off. This could be preventing the transition effect from taking place.

I would suggest updating your approach to just toggle the active class on the h2 element. Unfortunately, I am not very familiar with Angular to provide specific guidance on this issue.

If you inspect the h2 element in Chrome dev tools while clicking on it in your plnkr example, you will see the template transitioning from:

      <!--template bindings={
  "ng-reflect-ng-if": "true"
}--><h2 class="login-title">Login</h2>
      <!--template bindings={
  "ng-reflect-ng-if": null
}-->

To:

      <!--template bindings={
  "ng-reflect-ng-if": null
}-->
      <!--template bindings={
  "ng-reflect-ng-if": "true"
}--><h2 class="login-title active">Down</h2>

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

There seems to be an issue with the functionality of the Django's div class alert alert-danger feature

Here is my custom code for handling user sign-up in Django: class SignUpForm(forms.ModelForm): name = forms.CharField(label="name", required=True, widget=forms.TextInput()) email = forms.CharField(label="email", required=True, ...

Javascript code creates a blur effect on webpage bodies

On my webpage, I have multiple elements, including a "change BG" button. When this button is clicked, I want to hide all other content on the page except for the button using JavaScript. Alternatively, clicking the button could blur out all other elements ...

Issue with Inline JavaScript in `href` tag not functioning correctly in Firefox

I am encountering an issue with this inline JavaScript not working in Firefox. I need to figure out how to make it function correctly in Firefox. <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style> ...

How to incorporate a background image using CSS in Ruby on Rails 2

I created a scaffold using ruby and now I'm trying to add a background image to all pages of the website. However, I am uncertain about what the correct image link should be. The image is located in app/assets/images/"dep.jpg" This is what I have at ...

Leveraging the Bootstrap 3 audio player, although displaying a standard HTML5 output

When trying to use the Bootstrap 3 player to display an audio player, I'm encountering an issue where the page only shows a default black HTML5 audio player output. Here is my current directory structure: miuse/ application/ bootstrap/ ...

How to access a webpage on your Android device without the address bar visible

My question relates to sending Push Notifications through OneSignal. Upon clicking a push notification, it automatically redirects the user to my website. Is there a way to hide the address bar on the browser when this happens? I attempted using the follo ...

Seamless transition animation using jquery

I'm attempting to create a smoother transition when the button is clicked, but so far it's not working as expected. I tried using $slideToggle, but I may have implemented it incorrectly. <button class="btn btn-warning" id="btn-m ...

Creating PDFs using Puppeteer in the presence of `link` tags

On my website, students have the ability to create their own notes using a RichText editor where the content can be quite complex. I want to provide them with an option to download these notes as a PDF file. To achieve this, I am planning to use the "puppe ...

As soon as I hit the submit button on my website form, the URL is automatically refreshed with the information I provided

I am a beginner when it comes to forms and recently copied and pasted this login snippet code: <div class="login-form-1"> <form id="login-form" class="text-left"> <div class="main-login-form"> <div class="login-group"> ...

Create a JavaScript alert script devoid of any instances of double quotation marks

This snippet belongs to my webpage: <span onclick=alert('Name:$commenter_name <br>Email:$commenter_email <br> Rate:$commenter_rate <br>Comment time:$currentdate <br>Comment:$commenter_comment')>$commenter_name:$comm ...

Problem with the appearance of the drop-down menu

After a few dedicated weeks on a Web application project, I am currently tackling the challenge of a drop-down menu. Despite its functionality, there are two specific points I need help with: When expanding the menu by selecting a main item, I want to pr ...

Combining left-aligned and centered elements within a grid using flexbox

Looking to create a fluid responsive grid layout using flexbox, without the need for media queries. The number of elements in the grid can vary and each item should have a fixed, equal width with left alignment. The entire group should have equal left and ...

Is there a way to eliminate the number spinner in Angular specifically for certain input fields?

I am facing an issue where I need to remove the numeric spinner from only a few selected inputs. By adding the following code snippet to my styles.scss file, I was able to successfully remove the spinner: /* Chrome, Safari, Edge, Opera */ input[matinput]: ...

Ways to eliminate unused classes from JQuery UI

We have successfully implemented JQuery UI library for enhancing our interface. However, since we no longer need to support outdated browsers like IE6, classes such as .ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl are unnecessary and clu ...

How to Transform a Navigation Bar into a Carousel

I am creating a website that is designed to be responsive. Currently, I have a horizontal navigation bar which collapses into a drop-down menu when the screen size decreases. When each tag in the menu is clicked, a different image loads into a designated ...

Tips for shrinking a sticky header when scrolling using Angular and JavaScript

Looking for a way to modify the header component in an Angular application so that it shrinks as the user scrolls down while maintaining its sticky functionality. How can I adjust the display of the lower half of the header to show no text when the user s ...

Perform the action as soon as the AJAX call is completed, without delaying the initiation of another AJAX call based on a set interval time

My webpage is experiencing slow retrieval of 10 images hosted on Amazon AWS. To improve loading speed, I am attempting to display a page without images and use AJAX calls to fetch them dynamically. The PHP script for fetching each image can take a long tim ...

Getting User Input with HTML and JavaScript

Whenever a user enters their first and last name in the message box, I have 3 functions that return (a) Their names merged in array form and (b) Their names merged as an array of objects. The issue arises when I test it in Google Chrome; nothing appears wh ...

Curious as to why body.scrollTop functions differently in Google Chrome and Firefox compared to Microsoft Edge

Up until recently, the code body.scrollTop was functioning correctly in my Chrome browser. However, I've noticed that now it is returning 0 in both Firefox and Chrome, but still giving the proper value in Microsoft Edge. Is there anyone who can assis ...

Gleaming personalized select input/selectize input

I am striving to customize my Shiny select input in the following ways: Eliminate the label Set a unique background color: #2f2d57 Include a placeholder Enable users to both type-in and select Despite my efforts, I have not been successful in alignin ...