javascript - Bootstrap 工具提示动态 CSS 规范

标签 javascript css angularjs twitter-bootstrap

Bootstrap默认的工具提示模板是黑框和白色文本。我可以像这样更改 .tooltip css 类:(白色背景。)

.tooltip{position:absolute;display:none;color:#333;text-align:left;font-size:0.9em;width:250px;}
.tooltip.in{opacity:0.9;z-index:1030;height:auto;display:block}
.tooltip.top{margin-top:-10px;text-align:center}
.tooltip.top{margin-top:-10px;text-align:center}
.tooltip.right{margin-left:10px}
.tooltip.bottom{margin-top:10px;text-align:center}
.tooltip.left{margin-left:-10px;text-align:right; position: absolute}
.tooltip-inner{display:inline-block;padding:10px;color:#666;background-color:white}
.tooltip-arrow{position:absolute;width:10px;height:0;}
.tooltip.top .tooltip-arrow{bottom:-5px;left:50%;margin-left:-5px;border-top-color:white;border-width:5px 5px 0}
.tooltip.right .tooltip-arrow{top:50%;left:-5px;margin-top:-5px;border-right-color:white;border-width:5px 5px 5px 0}
.tooltip.left .tooltip-arrow{top:50%;right:-5px;margin-top:-5px;border-left-color:white;border-width:5px 0 5px 5px}
.tooltip.bottom .tooltip-arrow{top:-5px;left:50%;margin-left:-5px;border-bottom-color:white;border-width:0 5px 5px}

我应该在 Angular Directive(指令)中动态更改工具提示的模板。

angular.module("app", []).directive("tooltip", function(){
    return {
        restrict: "A",
        scope: {
            title: "@",
            template: "@"
        },
        link: function(scope, element){
            $(element).tooltip({
                title: scope.title,
                placement: "right",
            });            
        }
    }
})

例如红色工具提示、蓝色工具提示......

<div ng-app="app">
    <a href="#" tooltip title="Title-1" template="red-tooltip">Title-1</a>
    <a href="#" tooltip title="Title-2" template="blue-tooltip">Title-2</a>
</div>

我无法应用不同的覆盖工具提示 CSS 类。

DEMO is here.

最佳答案

只需将链接功能更改为

    link: function(scope, element, attrs){
        $(element).tooltip({
            title: scope.title,
            placement: "right",
        }).addClass(attrs.template);
    }

关于javascript - Bootstrap 工具提示动态 CSS 规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32882482/

相关文章:

AngularJS 的 javascript 执行顺序

javascript - 由于 : TypeError: $stateProvider. 状态不是函数,无法实例化模块启动器

AngularJS 设置 SSL header

javascript - 应用悬停鼠标时 Accordion 不会停止

Javascript 时间戳限制为最后 8 个字符

css - wordpress 中的样式菜单

jquery - 在 tomcat 上运行 spring 应用程序时更新我的​​ html/css/js 文件的方法

php - 如何通过 jQuery 将 PHP 文件加载到 DIV 中?

javascript - 在 Electron 中创建从主进程到计算函数的不可见窗口

css - block 内绝对定位的 div,位置为 :fixed and scrollbars