cmc-web/packages/common/components/image-cropper/utils/effectRipple.js

43 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2024-08-20 12:11:31 +00:00
/**
* 点击波纹效果
*
* @param {[event]} e [description]
* @param {[Object]} arg_opts [description]
* @return {[bollean]} [description]
*/
2024-08-21 01:17:14 +00:00
export default function (e, arg_opts) {
const opts = Object.assign(
{
ele: e.target, // 波纹作用元素
type: 'hit', // hit点击位置扩散center中心点扩展
bgc: 'rgba(0, 0, 0, 0.15)' // 波纹颜色
},
arg_opts
),
target = opts.ele
2024-08-20 12:11:31 +00:00
if (target) {
2024-08-21 01:17:14 +00:00
const rect = target.getBoundingClientRect()
let ripple = target.querySelector('.e-ripple')
2024-08-20 12:11:31 +00:00
if (!ripple) {
2024-08-21 01:17:14 +00:00
ripple = document.createElement('span')
ripple.className = 'e-ripple'
ripple.style.height = ripple.style.width = Math.max(rect.width, rect.height) + 'px'
target.appendChild(ripple)
2024-08-20 12:11:31 +00:00
} else {
2024-08-21 01:17:14 +00:00
ripple.className = 'e-ripple'
2024-08-20 12:11:31 +00:00
}
switch (opts.type) {
case 'center':
2024-08-21 01:17:14 +00:00
ripple.style.top = rect.height / 2 - ripple.offsetHeight / 2 + 'px'
ripple.style.left = rect.width / 2 - ripple.offsetWidth / 2 + 'px'
break
2024-08-20 12:11:31 +00:00
default:
2024-08-21 01:17:14 +00:00
ripple.style.top = e.pageY - rect.top - ripple.offsetHeight / 2 - document.body.scrollTop + 'px'
ripple.style.left = e.pageX - rect.left - ripple.offsetWidth / 2 - document.body.scrollLeft + 'px'
2024-08-20 12:11:31 +00:00
}
2024-08-21 01:17:14 +00:00
ripple.style.backgroundColor = opts.bgc
ripple.className = 'e-ripple z-active'
return false
2024-08-20 12:11:31 +00:00
}
2024-08-21 01:17:14 +00:00
}