我发现 flexi 颜色选择器脚本可以为您提供基于纯 JavaScript 的颜色选择,但是它不允许拖动进行选择,只能单击调色板。
我从以下方面做了很少的修复:
if (slideElement.attachEvent) {
slideElement.attachEvent('onclick', slideListener(this, slideElement, pickerElement));
pickerElement.attachEvent('onclick', pickerListener(this, pickerElement));
} else if (slideElement.addEventListener) {
slideElement.addEventListener('click', slideListener(this, slideElement, pickerElement), false);
pickerElement.addEventListener('click', pickerListener(this, pickerElement), false);
}
至
if (slideElement.attachEvent) {
slideElement.attachEvent('onmouseup', slideListener(this, slideElement, pickerElement));
slideElement.attachEvent('onmousedown', slideListener(this, slideElement, pickerElement));
pickerElement.attachEvent('onmouseup', pickerListener(this, pickerElement));
pickerElement.attachEvent('onmousedown', pickerListener(this, pickerElement));
} else if (slideElement.addEventListener) {
slideElement.addEventListener('mouseup', slideListener(this, slideElement, pickerElement), false);
slideElement.addEventListener('mousedown', slideListener(this, slideElement, pickerElement), false);
pickerElement.addEventListener('mouseup', pickerListener(this, pickerElement), false);
pickerElement.addEventListener('mousedown', pickerListener(this, pickerElement), false);
}
它有效,但是只有在页面加载时才有效,如果你不止一次开始拖动背景图像,有没有办法解决这个问题?
另外可选的事情是让它改变颜色,同时按住鼠标按钮并尽可能拖动鼠标。