1

I need to add google webkit functionality to my application. I want something similar to what we have in gmail right now, where once we place the mouse over "+" symbol, it expands and provides us with various options like "insert photos', "insert links" etc. I am new to angularjs and any help will be greatly appreciated.

3
  • Sounds like you want to use a custom directive for the mouseover, start there. Commented Sep 11, 2013 at 19:53
  • any examples that you are aware of where someone has implemented webkit??! Commented Sep 11, 2013 at 20:03
  • Haven't seen GWT used with Angular, usually its one or the other. Commented Sep 11, 2013 at 20:06

2 Answers 2

3

You can make use of ng-mouseenter and ng-mouseleave, a simple directive such as this

myApp.directive('expando', function () {
return {
    restrict: 'A',
    scope: {
    },
    controller: ['$scope', function ($scope) {
        $scope.open = false;
    }],
    link: function ($scope, elem, attrs, ctrl) {

        $scope.toggleState = function () {
            if ($scope.open) {
                $scope.open = false;
            } else {
                $scope.open = true;
            }
        };
    },
    replace: true,
    transclude: true,
    template: '<div ng-mouseenter="toggleState()" ng-mouseleave="toggleState()"> <span ng-hide="open" class="sectionIndicator">+</span> <div ng-show="open" class="inline" ng-transclude></div> </div>'
};});

would probably do what you need. Here is a fiddle - http://jsfiddle.net/LukeMaso/LwFws/

Sign up to request clarification or add additional context in comments.

Comments

2

You can use ngMouseover, ngMouseleave and ngGlass for simple effect:

HTML

<!DOCTYPE html>
<html data-ng-app="demoApp">
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js"></script>
        <link rel="stylesheet" href="style.css" />
        <script src="script.js"></script>
    </head>
    <body>
        <h1>Hello Plunker!</h1>
        <div class="menu" data-ng-controller="MenuController">
            <div class="button" data-ng-mouseover="expand($event)" data-ng-class="{hidden:expanded}">
                +
            </div>
            <div class="button-shell" data-ng-class="{expanded:expanded}" data-ng-mouseleave="collapse($event)">
                <div class="button">
                    1
                </div>
                <div class="button">
                    2
                </div>
                <div class="button">
                    3
                </div>
            </div>
        </div>
    </body>
</html>

JS

var m = angular.module('demoApp', []);

m.controller('MenuController', ['$scope', function($scope){
    $scope.expanded = false;

    $scope.expand = function(event){
        $scope.expanded = true;
    }

    $scope.collapse = function(event){
        $scope.expanded = false;
    }
}]);

CSS

.menu {
    background-color: #f5f5f5;
    border-top: 1px solid #cfcfcf;
    height: 31px;

    cursor: pointer;
}

.button-shell {
    height: 31px;
    display: none;
}

.button {
    height: 31px;
    width: 31px;

    line-height: 31px;
    text-align: center;

    display: inline-block;
}

.hidden {
    display: none;
    opacity: 0;
}

.expanded {
    display: inline-block;
}

See this plunker for a demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.