【问题标题】:how to autohide the ui-bootstrap tooltip如何自动隐藏 ui-bootstrap 工具提示
【发布时间】:2017-07-13 11:56:21
【问题描述】:

我正在使用https://angular-ui.github.io/bootstrap/ 在使用 AngularJS 开发的 html 页面中显示工具提示。我可以访问 tooltip-is-open 属性来显示和隐藏工具提示。但是我无法使用自定义指令来实现相同的目标。

<!DOCTYPE html>
<html lang="en-US">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
    <script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
    <link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<body>

<div ng-app="myApp" ng-controller="myCtrl">
  <button tooltip-placement="auto" uib-tooltip="Hide/show tooltip using directive" tooltip-trigger="'click'" tooltip-is-open="true" tooltip-auto-hide>Button 1</button>
  <button tooltip-placement="right" uib-tooltip="Hide/show tooltip using controller" tooltip-trigger="'click'" tooltip-is-open="showHidett" tooltip-auto-hide>Button 2</button>
</div>

<script type="text/javascript">
var app = angular.module('myApp', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
app.controller('myCtrl', function($scope,$timeout) {
    $scope.showHidett = true;
    $timeout(function () {
         $scope.showHidett = false;
    }, 2000);

});
app.directive('tooltipAutoHide',function($timeout){
    return {
        restrict: 'A',
        scope:{
            tooltipIsOpen :'='
        },
        link: function(scope, element, attrs){
            element.on('mouseenter', function () {
                scope.tooltipIsOpen = true;
                $timeout(function () {
                    scope.tooltipIsOpen = false;
                }, 2000);
            });
            element.on('mouseleave', function () {
                scope.tooltipIsOpen = false;
            });
        }
    };
});

</script>
</body>
</html>

当我运行代码时,由控制器管理的 Button2 的工具提示触发器正在工作,但由指令管理的 Button1 的工具提示触发器不工作。工作示例发布在以下 plunker 链接https://plnkr.co/edit/0bwCpPVYDAUiQkW6oIu3?p=preview

【问题讨论】:

标签: angularjs twitter-bootstrap


【解决方案1】:

按照https://angular-ui.github.io/bootstrap/的指导方针

您可以使用tooltip-popup-close-delay 指令来应用隐藏延迟, 和tooltip-trigger 接受多个以空格分隔的值,如mouseenter click 无需绑定外部鼠标输入事件

请参阅这些属性的定义,

【讨论】:

  • tooltip-popup-close-delay 用于只是延迟隐藏工具提示,而不是隐藏工具提示。而且我手动覆盖触发器只是为了在特定时间间隔后隐藏工具提示。
  • 您想在点击或悬停时打开工具提示吗?
  • 在使用隔离作用域时,您可能没有像这样直接赋值tooltip-is-open="tooltipIsOpen"plnkr.co/edit/9zWieWIRqlkRuuJoEmTa?p=preview
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-21
  • 1970-01-01
  • 2021-08-27
相关资源
最近更新 更多