jquery - 将条件样式从 jQuery 迁移到 AngularJS

标签 jquery css angularjs

我正在制作我的第一个 Angular 应用程序,并且正在努力解决在 AngularJS 中有条件地设置 DOM 样式背后的思维过程。

我以前在 jQuery 中这样做是这样的:

containerWidth = lineWidth/numberOfObjects; $container.css('width',containerWidth);

因此,如果有 1 个对象,则宽度为 100%,如果有 5 个,则宽度变为 20%。

我不确定是在链接中、在指令中还是在 Controller 本身中执行此操作?

最佳答案

请参阅ng-style

例子:

<div ng-style="divStyle" />

和JS:

$scope.divStyle = {'width' : (lineWidth / numberOfObjects) + 'px;' };

(我不知道 lineWidth 是从哪里来的......但就是这个想法)

关于jquery - 将条件样式从 jQuery 迁移到 AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32246801/

相关文章:

ios - 使用 "-webkit-overflow-scrolling: touch"时停止过度滚动?

css - 所有 Windows 浏览器的@font-face 问题

javascript - 错误: $injector:modulerr Module Error seems there is an injection error in my directive but I don't understand whats wrong in my code

javascript - 为嵌套对象创建新行

javascript - angular js日期输入格式

javascript - JQUERY 检索和删除 previous sibling 姐妹

html - 带下拉菜单的 <ul> 的 CSS 样式

javascript - 向下滚动页面加载的最佳方式

javascript - 在没有 jquery 的情况下检测多个类名

javascript - 如何循环遍历数组并使用该值来尝试查找对象名称