index.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React, { useEffect, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import MenuSider from '@/components/MenuSider'
  4. const fullNum = {
  5. width: window.innerWidth,
  6. height: window.innerHeight
  7. }
  8. function A5view() {
  9. const iframeDom = useRef<any>(null)
  10. const [txt, setTxt] = useState({
  11. title: '',
  12. show: false
  13. })
  14. useEffect(() => {
  15. // 点击图片
  16. ;(window as any).clickObject = (val: any) => {
  17. console.log('000', val)
  18. }
  19. // 鼠标移入
  20. ;(window as any).hoverObject = (name: any) => {
  21. setTxt({
  22. title: name,
  23. show: true
  24. })
  25. }
  26. // 鼠标移出
  27. ;(window as any).mouseoutObject = () => {
  28. setTxt({
  29. title: '',
  30. show: false
  31. })
  32. }
  33. const txtDom: any = document.querySelector('.txt')
  34. if (txtDom) {
  35. // 获取鼠标坐标
  36. ;(window as any).mouseLoc = (x: any, y: any) => {
  37. // console.log("ppp", x, y);
  38. // 最大X值
  39. const maxX = fullNum.width - 200
  40. let xRes = x >= maxX ? maxX : x
  41. // xRes = xRes - 100 <= 0 ? 0 : xRes - 100;
  42. // 最大y值
  43. const domHeight = txtDom.clientHeight
  44. const maxY = fullNum.height - domHeight
  45. let yRes = y >= maxY ? maxY : y
  46. // yRes = yRes - domHeight / 2 <= 0 ? 0 : yRes - domHeight / 2;
  47. txtDom.style.top = yRes + 'px'
  48. txtDom.style.left = xRes + 'px'
  49. }
  50. }
  51. }, [])
  52. return (
  53. <div className={styles.A5view}>
  54. <iframe
  55. id='iframe'
  56. ref={iframeDom}
  57. title='3d'
  58. src='./three/index.html'
  59. frameBorder='0'
  60. ></iframe>
  61. <div className='txt' style={{ opacity: txt.show ? 0.8 : 0 }}>
  62. <h2>{txt.title}</h2>
  63. </div>
  64. <MenuSider isSidebarOpen={false} />
  65. </div>
  66. )
  67. }
  68. const MemoA5view = React.memo(A5view)
  69. export default MemoA5view