Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fade in and then fade out text inside a <div>

Tags:

angularjs

My Web page has the following tag:

<div data-ng-model="modal.data.message"></div>

Is there a simple way using that I can make a message "autosaving" fade into view in the <div> and then fade out a couple of seconds after the function returns.

like image 701
Samantha J T Star Avatar asked Oct 26 '13 14:10

Samantha J T Star


1 Answers

Add the ngShow directive to your div:

<div ng-model="message" ng-show="showMessage" class="message fadein fadeout">{{message}}</div>

When saving begins set showMessage = true and the message you want to display. When saving is done set showMessage = false. To show the message a while longer after the saving is done you can use $timeout:

// Loadind done here - Show message for 3 more seconds.
$timeout(function() {
    $scope.showMessage = false;
}, 3000);

The animation part depends on what version of AngularJS you are using.

Here is an example using 1.2: http://plnkr.co/edit/jBukeP?p=preview

like image 146
tasseKATT Avatar answered Sep 28 '22 07:09

tasseKATT