在我的下面的示例中,遮罩在绿色和蓝色线上起作用,但会让水平的红线完全消失。当移除遮罩时,红线似乎没有问题。出了什么问题?
document.querySelector('button').addEventListener('click', function(){
document.getElementById('problem-line').removeAttribute('mask')
}, false)
<svg width="400" height="180">
<defs>
<g id='circle'>
<circle r="50" cx="100" cy="100" />
</g>
<mask id="hole">
<rect width="100%" height="100%" fill="white" />
<use xlink:href="#circle" />
</mask>
</defs>
<use xlink:href="#circle" opacity='0.5' />
<line id='problem-line' x1='100' y1='100' x2='300' y2='100' stroke='red' mask="url(#hole)" />
<line x1='100' y1='100' x2='300' y2='50' stroke='green' mask="url(#hole)" />
<line x1='100' y1='100' x2='300' y2='150' stroke='blue' mask="url(#hole)" />
</svg>
<div>
<button>Remove mask</button>
</div>