javascript - Use image to fill a SVG polygon -


this continuation of good way map custom-shaped html elements responsively board game

there 3 polygons @ bottom of board need have image fill. i've attempted use

background:url(image.png);  background-size:cover; 

and

<defs ng-if="$parent.cool.di.models.spaces[space].img">     <pattern id="img-{{space}}" patternunits="userspaceonuse" points="{{points}}">          <image xlink:href="{{cool.di.models.spaces[space].img}}"  />     </pattern> </defs> <svg ng-style="{position:'absolute', background:'none', overflow: 'visible'}">     <g>          <polygon points="{{points || '0,0 0,10 10,10 10,0 0,0'}}" stroke="black" fill="{{bgcolor || 'gray'}}"></polygon>     </g> </svg> 

the variable 'points' derived function takes inner view dimensions normalize pixels match percentages.

thanks!

[edit]

<defs ng-if="cool.di.models.spaces[space].img">      <pattern         id="img-{{cool.di.models.spaces[space].color}}"         patternunits="userspaceonuse"         width="{{points.split(' ')[2].split(',')[0] - points.split(' ')[0].split(',')[0]}}"         height="{{points.split(' ')[2].split(',')[1] - points.split(' ')[0].split(',')[1]}}">             <image                  xlink:href="{{cool.di.models.spaces[space].img}}"                  ng-attr-x="{{points.split(' ')[0].split(',')[0]}}"                  ng-attr-y="{{points.split(' ')[0].split(',')[1]}}"                  height="100%"                  width="100%"                  stroke="black"                  style="border:5px solid black"></image>     </pattern> </defs> <svg ng-style="{position:'absolute', background:'none', overflow: 'visible'}">     <g>          <polygon               ng-attr-points="{{points}}"               stroke="black"               fill="{{cool.di.models.spaces[space].img ? 'url(#img-'+cool.di.models.spaces[space].color+')' : bgcolor || 'gray'}}">           </polygon>     </g> </svg> 

bottom white spaces need filled image.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -