声脉桥梁云监控平台

waves.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import './waves.css'
  2. export default{
  3. bind(el, binding) {
  4. el.addEventListener('click', e => {
  5. const customOpts = Object.assign({}, binding.value)
  6. const opts = Object.assign({
  7. ele: el, // 波纹作用元素
  8. type: 'hit', // hit点击位置扩散center中心点扩展
  9. color: 'rgba(0, 0, 0, 0.15)' // 波纹颜色
  10. }, customOpts)
  11. const target = opts.ele
  12. if (target) {
  13. target.style.position = 'relative'
  14. target.style.overflow = 'hidden'
  15. const rect = target.getBoundingClientRect()
  16. let ripple = target.querySelector('.waves-ripple')
  17. if (!ripple) {
  18. ripple = document.createElement('span')
  19. ripple.className = 'waves-ripple'
  20. ripple.style.height = ripple.style.width = Math.max(rect.width, rect.height) + 'px'
  21. target.appendChild(ripple)
  22. } else {
  23. ripple.className = 'waves-ripple'
  24. }
  25. switch (opts.type) {
  26. case 'center':
  27. ripple.style.top = (rect.height / 2 - ripple.offsetHeight / 2) + 'px'
  28. ripple.style.left = (rect.width / 2 - ripple.offsetWidth / 2) + 'px'
  29. break
  30. default:
  31. ripple.style.top = (e.pageY - rect.top - ripple.offsetHeight / 2 - document.body.scrollTop) + 'px'
  32. ripple.style.left = (e.pageX - rect.left - ripple.offsetWidth / 2 - document.body.scrollLeft) + 'px'
  33. }
  34. ripple.style.backgroundColor = opts.color
  35. ripple.className = 'waves-ripple z-active'
  36. return false
  37. }
  38. }, false)
  39. }
  40. }