【发布时间】:2014-06-11 03:56:18
【问题描述】:
我希望我不会在这里遗漏一些明显的东西,但我正在尝试学习 Angular,但在尝试制定指令时遇到了问题。
我正在尝试构建一个指令,该指令将从数据属性(“背景图像”)中获取 url,并将其作为背景图像应用于伪元素,但我无法确定如何定位::before 元素,或者即使 Angular 可以修改伪元素。
这是我正在尝试构建的指令: http://cdpn.io/cqvGH
我可以让它将背景应用到 div.item 但是当我尝试定位 ::before no joy.
这是指令代码:
angular.module('testApp', [
])
angular.module('testApp')
.directive('backgroundImage', function(){
return function(scope, element, attrs){
restrict: 'A',
attrs.$observe('backgroundImage', function(value) {
// If I remove ::before it will apply image background to .item correctly.
element::before.css({
'background-image': 'url(' + value +')'
});
});
};
});
【问题讨论】:
标签: javascript jquery html css angularjs