-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (28 loc) · 925 Bytes
/
Copy pathscript.js
File metadata and controls
31 lines (28 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
let rect = document.getElementById('center')
rect.addEventListener('mousemove', (e)=>{
/* console.log(rect.getBoundingClientRect())
console.log(e.clientX) */
let rectangleloc = rect.getBoundingClientRect()
let x = e.clientX-rectangleloc.left;
let y = e.clientY-rectangleloc.right;
//console.log(x)
if(x<rectangleloc.width/2){
let redcolor = gsap.utils.mapRange(0, rectangleloc.width/2, 255, 0, x)
gsap.to(rect, {
backgroundColor: `rgb(${redcolor}, 0, 0)`,
ease: Power4,
})
}else{
let bluecolor = gsap.utils.mapRange(rectangleloc.width/2, rectangleloc.width,0, 255, x)
gsap.to(rect, {
backgroundColor: `rgb(0, 0, ${bluecolor})`,
ease: Power4,
})
}
})
rect.addEventListener('mouseleave', (e)=>{
gsap.to(rect, {
backgroundColor: `white`,
ease: Power4,
})
})