【发布时间】:2019-01-31 07:07:36
【问题描述】:
在 jquery 中,我们对此进行了切换。
如果我在做 jquery DIY,我会将“on”和“off”填充颜色存储在元素的“data”属性中,并根据需要检索每个颜色。
在 Konva 中实现鼠标悬停填充颜色切换的有效方法是什么?
示例:假设我有一个图层,在这个图层上我有一个包含矩形的组。通过在鼠标悬停时更改其填充颜色并在鼠标退出时恢复正常来突出显示矩形的鼠标悬停和鼠标悬停切换可能是
rect.on('mouseover', function(evt){
var shape = evt.target;
// Uh-oh, I need to stash the current fill color somewhere
shape.fill('lime');
})
rect.on('mouseexit', function(evt){
var shape = evt.target;
shape.fill('that_stashed_fill_color'); // < how to get the stashed val and from where ?
})
有什么想法吗?
编辑:我自己的尝试是使用
rect.on('mouseover', function(evt){
var shape = evt.target;
$(shape).data('bgColor', shape.fill()); // stash current in data
shape.fill('lime');
})
rect.on('mouseexit', function(evt){
var shape = evt.target;
shape.fill($(shape).data('bgColor')); // get the stashed val from jq data
})
这可行,但使用 jq 包装器感觉像是我希望避免的开销。
【问题讨论】:
标签: konvajs