【发布时间】:2014-03-16 15:28:19
【问题描述】:
我是 angularJS 的新手,我想弄清楚如何执行一个 jquery 函数,该函数允许我在每个图像的 div 容器上绘制一个 SVG,该容器通过 ng-repeat 指令具有“范围”的 ID。
partial.html
<div class="cover-cont" ng-repeat="project in projects" dv-list-projects>
<a href="#/project/{{project.slug}}">
<div class="cover" id="{{project.slug}}">
<img ng-src="{{project.custom_fields.projectCover}}">
</div>
</a>
</div>
我的 jquery 函数:
$('.cover').each(function(i, e){
var id = $(this).attr('id');
var img = $(this).find('img').attr('src');
var iw = $(this).find('img').width();
var ih = $(this).find('img').height();
var draw = SVG(id).size(iw , ih);
var svgImg = draw.image(img).size(iw,ih);
svgImg.filter(function(add) {
console.log('filter');
add.colorMatrix('saturate', 0.5);
});
var polygon = draw.polygon('0,0 '+ iw +',0 0,'+ih);
svgImg.clipWith(polygon);
});
所以,我需要获取 src,.cover div 的 Id,但我仍然有 {{project.slug}} 之类的字符串,而不是 .cover id 的此范围的值。
希望你能给出一些关于这个论点的最佳方法。
谢谢。
【问题讨论】:
标签: javascript jquery html angularjs svg