You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用VexFlow EasyScore更改加线颜色?

修改VexFlow EasyScore深色背景下的加线颜色

你之前尝试的setLedgerLineStyle并非VexFlow官方有效API,所以无法生效。可以通过以下两种方式修改加线颜色:

方法一:通过Stave样式全局设置

直接给stave设置样式对象,指定ledgerLineColor属性即可:

const {Factory} = Vex.Flow;
// Create a VexFlow renderer attached to the DIV element with id="output"
const vf = new Factory({renderer: {elementId: 'output', width: 200}});
const score = vf.EasyScore();
const system = vf.System();
// Create a 4/4 treble stave and add a voice
const stave = system.addStave({
    voices: [
        score.voice(score.notes(`${noteName}6/w`)),
    ]
}).addClef('treble');
stave.context.setStrokeStyle('white');
stave.context.setFillStyle('white');

// 设置加线颜色
stave.setStyle({
  ledgerLineColor: 'white'
});

vf.draw();

方法二:遍历加线逐个设置颜色

如果方法一不生效,可直接获取所有加线对象,逐个设置颜色:

const {Factory} = Vex.Flow;
// Create a VexFlow renderer attached to the DIV element with id="output"
const vf = new Factory({renderer: {elementId: 'output', width: 200}});
const score = vf.EasyScore();
const system = vf.System();
// Create a 4/4 treble stave and add a voice
const stave = system.addStave({
    voices: [
        score.voice(score.notes(`${noteName}6/w`)),
    ]
}).addClef('treble');
stave.context.setStrokeStyle('white');
stave.context.setFillStyle('white');

// 遍历加线设置颜色
stave.getLedgerLines().forEach(ledgerLine => {
  ledgerLine.setColor('white');
});

vf.draw();

注意:必须在vf.draw()执行前完成颜色设置,才能确保绘制时应用新颜色。

内容的提问来源于stack exchange,提问作者Samuel Gfeller

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 00:25:23