zent
Version:
一套前端设计语言和基于React的实现
55 lines (54 loc) • 1.59 kB
JavaScript
export function calculateChange(e, skip, props, container) {
!skip && e.preventDefault();
var containerWidth = container.clientWidth;
var containerHeight = container.clientHeight;
var x = typeof e.pageX === 'number' ? e.pageX : e.touches[0].pageX;
var y = typeof e.pageY === 'number' ? e.pageY : e.touches[0].pageY;
var left = x - (container.getBoundingClientRect().left + window.pageXOffset);
var top = y - (container.getBoundingClientRect().top + window.pageYOffset);
if (props.direction === 'vertical') {
var h = void 0;
if (top < 0) {
h = 359;
}
else if (top > containerHeight) {
h = 0;
}
else {
var percent = -((top * 100) / containerHeight) + 100;
h = (360 * percent) / 100;
}
if (props.hsl.h !== h) {
return {
h: h,
s: props.hsl.s,
l: props.hsl.l,
a: props.hsl.a,
source: 'rgb',
};
}
}
else {
var h = void 0;
if (left < 0) {
h = 0;
}
else if (left > containerWidth) {
h = 359;
}
else {
var percent = (left * 100) / containerWidth;
h = (360 * percent) / 100;
}
if (props.hsl.h !== h) {
return {
h: h,
s: props.hsl.s,
l: props.hsl.l,
a: props.hsl.a,
source: 'rgb',
};
}
}
return null;
}