MCPcopy Create free account
hub / github.com/codrops/OnScrollShapeMorph / render

Method render

js/interactive-tilt.js:64–80  ·  view source on GitHub ↗

* Animation loop that applies the tilt effect based on the cursor position.

()

Source from the content-addressed store, hash-verified

62 * Animation loop that applies the tilt effect based on the cursor position.
63 */
64 render() {
65 // Interpolate the current transform values towards the target values
66 // based on the cursor's position on the screen
67 this.imgTransforms.x = lerp(this.imgTransforms.x, map(cursor.x, 0, winsize.width, this.options.valuesFromTo.x[0], this.options.valuesFromTo.x[1]), this.options.amt);
68 this.imgTransforms.y = lerp(this.imgTransforms.y, map(cursor.y, 0, winsize.height, this.options.valuesFromTo.y[0], this.options.valuesFromTo.y[1]), this.options.amt);
69 this.imgTransforms.rz = lerp(this.imgTransforms.rz, map(cursor.x, 0, winsize.width, this.options.valuesFromTo.rz[0], this.options.valuesFromTo.rz[1]), this.options.amt);
70
71 // Apply rotation on the X and Y-axis only if perspective is enabled
72 this.imgTransforms.rx = !this.options.perspective ? 0 : lerp(this.imgTransforms.rx, map(cursor.y, 0, winsize.height, this.options.valuesFromTo.rx[0], this.options.valuesFromTo.rx[1]), this.options.amt);
73 this.imgTransforms.ry = !this.options.perspective ? 0 : lerp(this.imgTransforms.ry, map(cursor.x, 0, winsize.width, this.options.valuesFromTo.ry[0], this.options.valuesFromTo.ry[1]), this.options.amt);
74
75 // Apply the calculated transform values to the wrap element to create the 3D tilt effect
76 this.DOM.wrapEl.style.transform = `translateX(${this.imgTransforms.x}px) translateY(${this.imgTransforms.y}px) rotateX(${this.imgTransforms.rx}deg) rotateY(${this.imgTransforms.ry}deg) rotateZ(${this.imgTransforms.rz}deg)`;
77
78 // Continue the loop with the next animation frame
79 requestAnimationFrame(() => this.render());
80 }
81}

Callers 10

constructorMethod · 0.95
maFunction · 0.80
naFunction · 0.80
CaFunction · 0.80
JaFunction · 0.80
gsap.min.jsFile · 0.80
GtFunction · 0.80
TweenFunction · 0.80
PtFunction · 0.80

Calls 2

lerpFunction · 0.90
mapFunction · 0.90

Tested by

no test coverage detected