Animate the div block upon the initialization of the Angular View

Within this JSFiddle, there is a demonstration of a block that slides in from the left after a delay of two seconds.

(function (angular) {
    'use strict';

    angular.module('testApp', [])
        .controller('TestCtrl', function ($scope, $timeout) {
            $scope.title = "Hello";

            $scope.show = false;

            $timeout(function () {
                $scope.show = true;
            }, 2000);
        });

})(angular);

The objective is to have the block slide in as soon as the view loads, becoming visible to the user.

An existing CSS style can be utilized to achieve the sliding effect on the block.

.left-inner-nav {
    position:absolute; 
      top:0; 
      /*left:75px;*/
      left: -150px;
      width: 150px; 
      bottom: 0; 
      background:#2792D9;
    -webkit-transition: left 2s ease;
    -moz-transition: left 2s ease;
    -ms-transition: left 2s ease;
    -o-transition: left 2s ease;
    transition: left 2s ease;
}

.left-inner-nav-animate {
    left: 0;
}

Implementing this slide-in animation upon view load is the current challenge.

Answer №1

This is the purpose of using ngAnimate.

ngAnimate introduces 4 classes to handle different ngView states.

<style>
.slide.ng-enter { }        /* initial animations for enter */
.slide.ng-enter.ng-enter-active { } /* final animations for enter */
.slide.ng-leave { }        /* initial animations for leave */
.slide.ng-leave.ng-leave-active { } /* final animations for leave */
</style>

To use ngAnimate, download and include a reference to angular-animate.js. Then, make ngAnimate a dependency in your module.

angular.module('testApp', ['ngAnimate']);

Update

HTML Markup:

<div ng-view class="left-inner-nav"></div>

CSS Styles:

.left-inner-nav.ng-enter {} /* initial animations for enter */
.left-inner-nav.ng-enter.ng-enter-active {} <style>

.slide.ng-enter { } /* initial animations for enter / .slide.ng-enter.ng-enter-active { } / final animations for enter */

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

Utilizing the power of Ajax for enhancing table sorting and filtering functionality

Having an issue using JQuery tablesorter to paginate a table with rows fetched from the database. //list players by points (default listing) $result=mysql_query("select * from players order by pts_total") or die(mysql_error()); echo "<table id='li ...

Modifying the color of a placeholder in an HTML input using CSS

Version 4 of Chrome now supports the placeholder attribute on input[type=text] elements (and likely other browsers do too). Despite this, the following CSS code does not affect the color of the placeholder text: input[placeholder], [placeholder], *[pla ...

Blog Format Featuring Side-by-Side Columns

Is there a way to achieve horizontal columns that don't cut off articles and flow seamlessly into the next column? I want the columns to have varying heights, such as Post A at 60% height, followed by Post B at 40% height, then Post C at 30%, and fina ...

Tips for altering the input language of CKEditor using ASP.Net C#

Within my project, I am utilizing CKEditor and am in need of setting its input language to Farsi. I have successfully accomplished this task with certain textboxes and textareas by using a .js file called "FarsiType.js". The link to FarsiType.js is provi ...

Updating data in AngularJS after inserting a new record

What is the most efficient method to update comments data when a new record is added to the database? I currently have this code that works well, but I am concerned that it may be slow if there are a large number of comments. Any assistance would be greatl ...

Angular 5 requires the Google Map API call to be made before initiating the http get request

I am experimenting with URL parameters to make a GET request and then use JSON output to drive a query in Google Maps. Currently, I have managed to make the embedded map function by sanitizing it and passing static data. However, when making the query call ...

Hiding or closing a modal in Angular JS

I am encountering difficulties when trying to close the Modal in Angular JS HTML <div class="container"> <div class="col-md-12" id="gridSet"> <div class="gridStyle adjustViewPort" ng-grid="gridOptions"></div&g ...

Creating the necessary user interface using JSON data.Here are some steps to follow

I am struggling to create a dynamic UI based on JSON data. The issue I'm facing is with looping through the data to generate the required elements. My Goal: Achieving a Dynamic UI from Static Code .switch { position: relative; display: inline- ...

Using Driver Wait Until Text in Selenium involves waiting for a specific text to appear on a

I'm currently experimenting with the driver wait function using this specific wait condition. My goal is to verify that the text displayed on a button is exactly "Sign Up". Below is the code snippet I am working with: driver.wait(until.elementTextIs( ...

Experimenting with an angularjs directive, not yielding the desired results

Trying to use a directive here, and all the resources I've found online seem to be a variation of what I have. Here is the directive I created: angular.module('App'); App.directive("scrollBottom", ["$interval", function ($interval) { retu ...

How should I proceed if a TypeScript definition file that I am relying on is lacking a specific definition?

I have encountered an issue while using the React type definitions for my project. The focus method is missing on elements in the array returned by the refs property, which prevents me from getting a specific example to work. The compiler error states: pro ...

PHP Random Background Image Selector

I have a PHP code that is currently displaying a random header image every time the page is refreshed. While this works fine, I now need to add specific background-position css properties to some of the images. For instance, I would like 'headerimage ...

The Bootstrap Navbar is occupying an excessive amount of room on compact screens

Currently, I am developing a responsive website using bootstrap 3. However, I am encountering an issue with the collapsed navbar. Instead of the normal height (i.e. height of one nav link item), it is taking up the total height of all the nav link items. Y ...

Determining Field of View (FOV) for a perspective camera in ThreeJS following a browser window resize

After changing the size of the browser window, I'm trying to determine the correct Three.JS camera FOV. I have looked at several related questions, but haven't found a solution yet: How to calculate fov for the Perspective camera in three js? C ...

Is it possible to edit and update remote data using ng-grid?

I have implemented ng-grid and I am attempting to automatically update a single model when there are changes in the grid-table data. To achieve this, I am utilizing the edit module of ng-grid. This snippet shows my controller code: # App definition app = ...

IDE: Unusual hues in HTML IDs and class parameter inputs

Netbeans is my new favorite tool, but I'm struggling to figure out how to change the font of html id and class parameter values. Right now, they're blending in with the tags and have a distracting background color. I've browsed through Tool ...

Unable to extract a particular value from a JSON data structure

This situation has been on my mind for a good couple of hours now. I have this json object with example values like so: { "events": [ { "id": 64714, "live": false, "start": "1399117500", "league_ ...

useEffect initiates all actions

I'm currently exploring hooks functionality within a Next.JS project. I've successfully used a useEffect to track scrolling behavior in order to dynamically change the content displayed in a header when the page is scrolled. const [ scrollY, setS ...

Is it possible in ES6 to extend from Error without including the constructor in the stack trace?

After attempting to create a custom HTTPError class by extending Error, I encountered an issue: class HTTPError extends Error { constructor(codeArg, message){ let code = codeArg || 500; super(message || http.STATUS_CODES[code]); // first li ...

The concept of dynamic inheritance within Struts2's Tiles plugin adds a new

I am currently utilizing the Struts2 framework in conjunction with the tiles 2.0.6 plugin for my web application. Within my webapp, there is a primary "base" layout that comprises of a header, a footer, and the main page content: <definition name="shar ...