Rai Rai - 6 months ago 90
HTML Question

How to: CSS3 animated Popup bubble and text Fade in effect with Angularjs

I have developed a CSS 3 animated popup bubble that will pop up above and enlarge. Once the pop up animation gets over, a text that is bound to

$scope
will get displayed with a fade-in effect. It uses Angular Animate API.

I am sharing it here so that the code can help out people who are searching for a similar solution. The code will work on Chrome. As for other browsers, I have not tested it.

Rai Rai
Answer

This is the HTML

<body>
    <div class="bubble"><div ng-controller="Fade" ng-show="bool" class="fade" ng-init="init()">{{data}}</div><div class="arrow"></div></div>
</body>

This is the CSS

.fade.ng-animate {
        transition: 0.5s linear all;
        opacity: 1;
    }

    .bubble {
        position: relative;
        display: inline-block;
        width: 200px;
        min-height: 50px;
        padding: 20px;
        background: #FFFFFF;
        border: #7F7F7F solid 4px;
        -webkit-border-radius: 20px;
        -moz-border-radius: 20px;
        border-radius: 20px;
        animation: popup 1.5s;
    }

    .arrow:before {
        content: "";
        position: absolute;
        bottom: -19.5px;
        left: calc(15% - 3px);
        border-style: solid;
        border-width: 18px 18px 0;
        border-color: #7F7F7F transparent;
        display: block;
        width: 0;
        z-index: 0;
        animation: arrow 2s;
    }

    .arrow:after {
        content: "";
        position: absolute;
        bottom: -15px;
        left: 15%;
        border-style: solid;
        border-width: 15px 15px 0;
        border-color: #FFFFFF transparent;
        display: block;
        width: 0;
        z-index: 1;
        animation: arrow 2s;
    }

    @keyframes popup {
        0% {
            top: 100px;
            width: 100px;
        }

        100% {
            top: 0px;
            width: 200px;
        }
    }

    @keyframes arrow {
        0% {
            top: inherit;
        }

        100% {
            top: inherit;
        }
    }

This is the Angularjs

angular.module('app', ['ngAnimate'])
    .controller('Fade', ['$scope', '$timeout', function ($scope, $timeout) {
        $scope.init = function () {
            $scope.data = "This text will fade-in";
            $timeout(function () {
                $scope.bool = true;
            }, 2000);
        };
    }]);
Comments