作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想做一个 Angular Directive(指令),它检查元素的高度,如果给定高度,我想向其附加另一个元素。我是 Angular 的新手,所以我不知 Prop 体该怎么做。这是我到目前为止所做的一个片段:
HTML:
<ul fadeouttxt>
<li ng-repeat="cars in cars.list" style="height:200px;">
<div>
<div class="cnt">
<h2>{{cars.title}}</h2>
<div class="desc" ng-bind-html="cars.description"></div>
</div>
</div>
</li>
</ul>
js:
.directive('fadeouttxt', function () {
return {
link: function (scope) {
$('div.cnt').filter(function() {
if( $(this).find('.desc').height() < 130) return;
$(this).append('<div class="fader"></div>');
});
}
};
});
<div class="fader"></div>
是一个使溢出文本淡出的元素...
那么,有人可以帮我吗?
最佳答案
你想要的是这样的:
HTML:
<ul>
<li ng-repeat="cars in cars.list" style="height:200px;">
<div>
<div class="cnt" fadeouttxt>
<h2>{{cars.title}}</h2>
<div class="desc" ng-bind-html="cars.description"></div>
</div>
</div>
</li>
</ul>
js:
.directive('fadeouttxt', function () {
return {
link: function (scope, element) {
if( element.find('.desc').height() < 130) return;
element.append('<div class="fader"></div>');
}
};
});
所以你不需要使用jquery。
关于javascript - AngularJS如何将元素附加到特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31068896/
我是一名优秀的程序员,十分优秀!