2016-04-22 70 views
0

使用噴射顏色方案填充SVG矩形的正確方法是什麼?在linearGradient中使用多個站點似乎不起作用。SVG - 使用噴射顏色方案填充矩形

編輯,我想用下列顏色漸變之一填充矩形。 enter image description here

+0

「噴氣配色方案」是不是一個標準的或任何東西,所以我假定大多數人(像我)不知道你指的是什麼,你可以更具體地說明你想要完成什麼? –

+0

http://cresspahl.blogspot.com/2012/03/expanded-control-of-octaves-colormap.html - 如果我正確理解這一點,您正試圖創建一個從紅色到藍色的彩虹漸變幷包含其間的顏色。它是否正確? – BSMP

+0

@BSMP:是的,這就是我想在這裏實現的。 –

回答

1

我編輯的MDN代碼彩虹例如

<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients --> 

<svg width="120" height="240" version="1.1" xmlns="http://www.w3.org/2000/svg"> 
    <defs> 
    <linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1"> 
     <stop offset="0%" stop-color="#d30000"/> 
     <stop offset="30%" stop-color="#ffff05"/> 
     <stop offset="50%" stop-color="#05ff05"/> 
     <stop offset="70%" stop-color="#05ffff"/> 
     <stop offset="100%" stop-color="#041ae0"/> 
    </linearGradient> 
    </defs> 

    <rect x="10" y="10" rx="15" ry="15" width="100" height="100" fill="url(#Gradient2)"/> 

</svg> 
在小提琴

https://jsfiddle.net/9bmvr5hd/

1

的BbwrR梯度在Mozilla's SVG - Gradients documentation使用的示例:

<svg width="120" height="240" version="1.1" xmlns="http://www.w3.org/2000/svg"> 
 
    <defs> 
 
     <linearGradient id="Gradient1"> 
 
     <stop class="stop1" offset="25%"/> 
 
     <stop class="stop2" offset="50%"/> 
 
     <stop class="stop3" offset="75%"/> 
 
     </linearGradient> 
 
     <linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1"> 
 
     <stop offset="25%" stop-color="blue"/> 
 
     <stop offset="50%" stop-color="black" stop-opacity="0"/> 
 
     <stop offset="75%" stop-color="red"/> 
 
     </linearGradient> 
 
     <style type="text/css"><![CDATA[ 
 
     #rect1 { fill: url(#Gradient1); } 
 
     .stop1 { stop-color: blue; } 
 
     .stop2 { stop-color: black; stop-opacity: 0; } 
 
     .stop3 { stop-color: red; } 
 
     ]]></style> 
 
    </defs> 
 
    
 
    <rect id="rect1" x="10" y="10" rx="15" ry="15" width="100" height="100"/> 
 
    <rect x="10" y="120" rx="15" ry="15" width="100" height="100" fill="url(#Gradient2)"/> 
 
    
 
</svg>

我換了紅色和藍色,調整偏移百分比的位置,以儘量使其看起來更像你的形象。你應該能夠改變顏色併爲其他人添加/刪除停止。