javascript - .style("background-position", function(){...}) not populating the attribute -
full code here: http://jsfiddle.net/rczun/5/
the important part @ end wish use sample data set correct "background-position" element according data set, log displays there iteration , data it's still not being assigned.
var container = d3.select('.icon-selection-container').attr('width',500); var s = container.selectall('.icon') .data(icon_defs); s.enter() .append('div') .attr({ class : 'icon icon-book' }) .style("background-image", "url('http://static.mabelslabels.com/images/booklabels2.png')") .style("background-position", function(d,i) { var bgpos = d.style.slice(20);//clean sample data console.log(bgpos); return bgpos; } );
you need remove ; @ end of value, work
var bgpos = d.style.slice(21,-1);
Comments
Post a Comment