0

As shown in this fiddle it's possible to render a CSS sprite in SVG using the foreignObject element.

However this isn't supported in IE, so I was wondering if there was another way to do it.

I suspect the answer may be no, because I found two unresolved questions on this (1,2)

I'm using d3.js so any answer that spells out the d3 way to do this would be a bonus.

Community
  • 1
  • 1
Derek Hill
  • 5,965
  • 5
  • 55
  • 74

1 Answers1

1

You could pick out parts of an image using a clipPath if necessary. Extend your jsfiddle like this to see what I mean...

<div class='source youtube'></div>
<svg width="100%" height="100%">
    <foreignObject height=50 width=50>
        <div class='source facebook'></div>
    </foreignObject>
    <defs>
        <clipPath id="c">
            <rect y="10" width="7" height="10"/>
        </clipPath>
        <clipPath id="c2">
            <rect x="7" y="12" width="7" height="10"/>
        </clipPath>
    </defs>
    <image transform="scale(4.5)" y="-5" width="40" height="20" xlink:href="https://s3.amazonaws.com/856/sprite.png" clip-path="url(#c)"/>
    <g transform="translate(-30, 0)">
    <image transform="scale(4.5)" x="0" y="0" width="40" height="20" xlink:href="https://s3.amazonaws.com/856/sprite.png" clip-path="url(#c2)"/>
    </g>
<svg>    
Robert Longson
  • 118,664
  • 26
  • 252
  • 242