当用户单击按钮时,我想将svg图像的描边宽度增加0.5。我已经有了单击函数,但不确定如何使函数起作用以增加描边宽度。
function pipeScaleFactorPlus(){
$(".pipe").style("stroke-width", "+=0.5");
drawMapPipes();
}
.pipe是SVG类,调用drawMapPipes()函数重新绘制SVG图像。
当用户单击按钮时,我想将svg图像的描边宽度增加0.5。我已经有了单击函数,但不确定如何使函数起作用以增加描边宽度。
function pipeScaleFactorPlus(){
$(".pipe").style("stroke-width", "+=0.5");
drawMapPipes();
}
.pipe是SVG类,调用drawMapPipes()函数重新绘制SVG图像。
$("button").click(function(evt) {
var myLine = $("line");
// Get the current stroke-width.
// Try getting it from the style object first. Otherwise get it direct
// from the attribute value.
// We use parseInt() to strip off any units ("20px" -> 20)
var currentWidth = parseInt(myLine.css("strokeWidth") || myLine.attr("stroke-width"), 10);
// Update the style property "strokeWidth".
// Note that the property has a different spelling to the attribute.
myLine.css("strokeWidth", 30 - currentWidth);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<svg>
<line y1="75" x2="300" y2="75" stroke="black" stroke-width="10"/>
</svg>
<button>Click me</button>
$("#increasePipe").click(function(){
map.pipeSize += 0.25;
if (map.pipeSize > map.pipeSizeMax){
map.pipeSize = map.pipeSizeMax;
}
map.svg.selectAll(".pipe").style("stroke-width", map.pipeSize);
});
style()
函数。您是否使用了其他添加该函数的插件? - Paul LeBeau