MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / changeBackground

Function changeBackground

src/layouts/BasicLayout.jsx:40–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38 } = props;
39 const userRole = localStorage.getItem('userRole')||'user';
40 const changeBackground = () => {
41 // 根据鼠标移动改变图片
42 let startingPoint = null
43 const snowContainer = document.getElementById('snow-container')
44 const header = document.getElementById('index-header')
45 const headerEnterListener = new WeakMap() // WeakMap类型 不计入垃圾回收机制
46 headerEnterListener.set(header, (e) => {
47 startingPoint = e.clientX
48 header.classList.add('moving')
49 })
50 header.addEventListener('mouseenter', headerEnterListener.get(header), false)
51
52 const headerOutListener = new WeakMap() // WeakMap类型 不计入垃圾回收机制
53 headerOutListener.set(header, (e) => {
54 header.classList.remove('moving')
55 header.style.setProperty('--percentage', 1)
56 snowContainer.style.visibility = 'inherit'
57 })
58 header.addEventListener('mouseout', headerOutListener.get(header), false)
59
60 const headerMoveListener = new WeakMap() // WeakMap类型 不计入垃圾回收机制
61 headerMoveListener.set(header, (e) => {
62 const percentage = (e.clientX - startingPoint) / window.outerWidth + 1
63 if (percentage < 0.5) {
64 snowContainer.style.visibility = 'hidden'
65 } else {
66 snowContainer.style.visibility = 'inherit'
67 }
68 header.style.setProperty('--percentage', percentage)
69 })
70 header.addEventListener('mousemove', headerMoveListener.get(header), false)
71
72 }
73 useEffect(() => {
74 changeBackground()
75 }, [])

Callers 1

BasicLayoutFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected