簡體   English   中英

SVG填充背景圖片

[英]SVG fill with background image

因此,我已經閱讀了很多問題,但到目前為止,沒有一個問題對我有用。

      <svg height="100%" width="100%" class="myclass">
        <polygon points="0,0 513,0 0,513" style="fill:red;" />
      </svg>

所以我的svg是紅色。 但是,我想將填充更改為圖像。

問題是,我希望能夠覆蓋此圖像。 例如,onClick更改SVG的背景圖像。

我一直在努力。

謝謝!

試試這個https://jsfiddle.net/2Lzo9vfc/62/

的HTML

<svg height="100%" width="100%" class="hover">
   <polygon class="shape" points="0,0 513,0 0,513" style="fill :red;" />
</svg>

<svg height="100%" width="100%" class="click">
   <polygon class="shape" points="0,0 513,0 0,513" style="fill :red;" />
</svg>

JS

$('.hover').hover(function(){
  $(this).find('polygon').css('fill', 'black');
},function(){
    $(this).find('polygon').css('fill', 'red');
});

$('.click').click(function() {
    $(this).find('polygon').css('fill', 'black');
});

第一個示例是hover更改,第二個示例是click

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM