【发布时间】:2018-06-05 19:26:08
【问题描述】:
以下问题:
我正在使用 ng-repeat 生成项目列表。如果用户点击我上面网页上的一个特殊标记,以下函数会收到一个事件并向下滚动到相应的项目。除了向下滚动之外,我还想突出显示该项目,直到用户再次移动鼠标。我的问题是,为此我需要操作我的 ng-repeat 列表中单个元素的 css 类。我认为这可能是可能的,因为每个 ng-repeat 元素都有自己的本地范围......但我没有找到解决方案。
我的部分指令:
//if a marker is clicked, the following code should bring the user to the corresponding item
$rootScope.$on("Scroll_to_product", function (event, args) {
product.gotoElement(args);
});
/*function which takes the class id of an html element as argument and brings
the user to the corresponding product*/
product.gotoElement = function (args) {
var elementID = 'product-' + args;
$location.hash(elementID);
// call $anchorScroll()
$anchorScroll();
}
任何帮助都会很棒,
谢谢,胡乔
【问题讨论】:
-
您可以在模板中使用
ng-classdocs.angularjs.org/api/ng/directive/ngClass 这是一个相关问题stackoverflow.com/questions/19331779/…
标签: javascript css angularjs