gpt4 book ai didi

javascript - 没有 Bootstrap 的 AngularJS 工具提示?

转载 作者:太空宇宙 更新时间:2023-11-04 13:03:38 24 4
gpt4 key购买 nike

我是 AngularJS 的新手,正在从事一个对外部依赖性非常严格的元素;事实上,Bootstrap 已被排除,但我必须实现“工具提示”指令。

我正在尝试使用 mouseenter 和 mouseleave 事件来做到这一点,但我想知道如何使用指令自己的属性作为工具提示的内容?

它会像这样使用:

<a id='someLink' my-tooltip='The content that I want to show'>Trigger</a>

作为 UI 开发的新手,谁能告诉我如何添加必要的 HTML/CSS 以通过指令完成这项工作?

最佳答案

DEMO

app.directive("tooltip", function () {
return {
link: function (scope, element, attrs) {

$(element).on("mouseover", function () {
$(this).append("<span>"+ attrs.tooltip +"</span>");
});

$(element).on("mouseout", function () {
$(this).find("span").remove();
});

scope.$on("$destroy", function () {
$(element).off("mouseover");
$(element).off("mouseout");
});
}
};
});

CSS Source

a.tooltips {
position: relative;
display: inline;
}
a.tooltips span {
position: absolute;
width:140px;
color: #FFFFFF;
background: #000000;
height: 30px;
line-height: 30px;
text-align: center;
visibility: hidden;
border-radius: 6px;
}
a.tooltips span:after {
content: '';
position: absolute;
top: 50%;
right: 100%;
margin-top: -8px;
width: 0; height: 0;
border-right: 8px solid #000000;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
}
a:hover.tooltips span {
visibility: visible;
opacity: 0.8;
left: 100%;
top: 50%;
margin-top: -15px;
margin-left: 15px;
z-index: 999;
}

关于javascript - 没有 Bootstrap 的 AngularJS 工具提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25293348/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com