1

In following d3.js snippet I am expecting appropriate rotate style to be applied when I use different browser. However the second style always overrides the first one.

   var degrees = Math.floor( Math.random() * 360 );
   box_tr.append('td')
    .attr('id', 'image')
    .append('img')
    .attr('id', 'myimage')
    .attr('src', imgurl)
    .attr('style',"-webkit-transform: rotate(" + degrees + "deg);")
    .attr('style',"-moz-transform: rotate(" + degrees + "deg);");

Is my expectation correct? What are the alternatives?

Manish Sapariya
  • 3,575
  • 3
  • 25
  • 34

2 Answers2

0

Try setting the styles, not attributes on the element.

var degrees = Math.floor( Math.random() * 360 );
   box_tr.append('td')
    .attr('id', 'image')
    .append('img')
    .attr('id', 'myimage')
    .attr('src', imgurl)
    .style('-webkit-transform',"rotate(" + degrees + "deg);")
    .style('-moz-transform',"rotate(" + degrees + "deg);");
Tom Gasson
  • 83
  • 4
0

This answer was useful in setting the appropriate style. I set following two styles on the image element itself, when adding the image in DOM.

img.style.webkitTransform = "rotate(180deg)";
img.style.MozTransform = "rotate(180deg)";
Community
  • 1
  • 1
Manish Sapariya
  • 3,575
  • 3
  • 25
  • 34