gpt4 book ai didi

html - 如何添加:active to menu element dynamically

转载 作者:行者123 更新时间:2023-11-28 06:27:35 24 4
gpt4 key购买 nike

我正在我的单页 angularjs 网络应用程序中动态构建菜单。

`<li ng-repeat="m in menu"><a href="#{{m.url}}">{{m.name}}</a></li>

我想在 anchor 标签中添加 active 类,以显示当前选择的页面是什么。

一个标签CSS:

 .cl-effect-4 a::after {
position: absolute;
top: 170%;
left: 0;
width: 100%;
height: 1px;
background: #fff;
content: '';
opacity: 0;
-webkit-transition: height 0.3s, opacity 0.3s, -webkit-transform 0.3s;
-moz-transition: height 0.3s, opacity 0.3s, -moz-transform 0.3s;
transition: height 0.3s, opacity 0.3s, transform 0.3s;
-webkit-transform: translateY(-10px);
-moz-transform: translateY(-10px);
transform: translateY(-10px);
}

.cl-effect-4 a:hover::after,
.cl-effect-4 a:focus::after,.cl-effect-4 a:active::after {
height: 5px;
opacity: 1;
-webkit-transform: translateY(0px);
-moz-transform: translateY(0px);
transform: translateY(0px);
}

我试过 ng-class="{active:getClass(m.url)}" 但这没有用,因为它只是添加了名为 active 的类。我需要通过属性激活 anchor 标记。

最佳答案

示例中 ngClass 表达式的右侧应该是一个 bool 值。因此,如果 getClass() 为真,将添加“事件”。您应该从 getClass 函数返回 true 或 false。

 $scope.getClass = function (path) {
if ($location.path().substr(0, path.length) === path) {
return true;
} else {
return false;
}

关于html - 如何添加:active to menu element dynamically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35173536/

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