Skip to content

Commit 20b6c29

Browse files
Code for the issue Dezenix#33 10DoC by Arpan Sharma after Changes
1 parent 5bc6367 commit 20b6c29

File tree

6 files changed

+301
-0
lines changed

6 files changed

+301
-0
lines changed

UI HOVER EFFECT/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## UI HOVER EFFECT
2+
3+
<h3> Tech Stack Used <img src = "https://media2.giphy.com/media/QssGEmpkyEOhBCb7e1/giphy.gif?cid=ecf05e47a0n3gi1bfqntqmob8g9aid1oyj2wr3ds3mg700bl&rid=giphy.gif" width = 32px> </h3>
4+
<p align="left"> <a href="https://www.w3.org/html/" target="_blank"> <img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/html5/html5-original-wordmark.svg" alt="html5" width="40" height="40"/> </a> <a href="https://www.w3schools.com/css/" target="_blank"> <img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/css3/css3-original-wordmark.svg" alt="css3" width="40" height="40"/> </a> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank"> <img src="https://raw.githubusercontent.com/devicons/devicon/master/icons/javascript/javascript-original.svg" alt="javascript" width="40" height="40"/> </a> </p>
5+
6+
### Preview
7+
8+
![]()
571 KB
Loading
41.2 KB
Loading

UI HOVER EFFECT/code/css/style.css

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#content {
2+
background-color: #f3f1fe;
3+
align-items: center;
4+
}
5+
6+
.parrot {
7+
border-radius: 50%;
8+
height: 130px;
9+
width: 130px;
10+
margin-top: -50%;
11+
padding-left: 10px;
12+
}
13+
14+
.card {
15+
16+
background-color: white;
17+
height: 400px;
18+
width: 400px;
19+
border-radius: 10px;
20+
margin: auto;
21+
margin-top: 100px;
22+
}
23+
24+
.card-text {
25+
width: 80%;
26+
padding-left: 40px;
27+
color: gray;
28+
text-align: center;
29+
padding-top: 100px;
30+
z-index: 1000;
31+
}
32+
33+
.para {
34+
text-align: center;
35+
font-size: larger;
36+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
37+
font-style: italic;
38+
line-height: 2;
39+
z-index: 1;
40+
}
41+
42+
.half-circle {
43+
width: 150px;
44+
height: 70px;
45+
position: absolute;
46+
left: 50%;
47+
top: -1px;
48+
transform: translateX(-50%);
49+
border-bottom-left-radius: 100px;
50+
border-bottom-right-radius: 100px;
51+
background: #f3f1fe;
52+
}
53+
54+
.comma-div {
55+
z-index: 999;
56+
position: absolute;
57+
font-size: 200px;
58+
margin-top: -400px;
59+
margin-left: 150px;
60+
color: gray;
61+
opacity: 0.1;
62+
}

UI HOVER EFFECT/code/index.html

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="./css/style.css">
9+
<title>Hover Card</title>
10+
</head>
11+
12+
<body id="content">
13+
14+
<div class="boxWrapper">
15+
<div class="half-circle">
16+
<div>
17+
<img src="../assets/parrot.jpg" alt="" class="parrot">
18+
</div>
19+
</div>
20+
<div class="card">
21+
<div class="card-text">
22+
<div>
23+
<p class="para">You want to know the difference between a master and a beginner? The master has
24+
failed more times than the beginner has even tried.</p>
25+
</div>
26+
27+
<div>
28+
<h4>MARVELLOUS MACAW</h4>
29+
</div>
30+
</div>
31+
32+
<div class="comma-div">
33+
<p class="comma">' '</p>
34+
</div>
35+
</div>
36+
37+
</div>
38+
39+
<script src="./js/tilt.js"></script>
40+
<script>
41+
VanillaTilt.init(document.querySelectorAll(".boxWrapper"), {
42+
max: 25,
43+
speed: 400
44+
});
45+
</script>
46+
</body>
47+
48+
</html>

UI HOVER EFFECT/code/js/tilt.js

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
var VanillaTilt = function () {
2+
"use strict";
3+
class t {
4+
constructor(e, i = {}) {
5+
if (!(e instanceof Node)) throw "Can't initialize VanillaTilt because " + e + " is not a Node.";
6+
this.width = null, this.height = null, this.clientWidth = null, this.clientHeight = null, this.left = null, this.top = null, this.gammazero = null, this.betazero = null, this.lastgammazero = null, this.lastbetazero = null, this.transitionTimeout = null, this.updateCall = null, this.event = null, this.updateBind = this.update.bind(this), this.resetBind = this.reset.bind(this), this.element = e, this.settings = this.extendSettings(i), this.reverse = this.settings.reverse ? -1 : 1, this.glare = t.isSettingTrue(this.settings.glare), this.glarePrerender = t.isSettingTrue(this.settings["glare-prerender"]), this.fullPageListening = t.isSettingTrue(this.settings["full-page-listening"]), this.gyroscope = t.isSettingTrue(this.settings.gyroscope), this.gyroscopeSamples = this.settings.gyroscopeSamples, this.elementListener = this.getElementListener(), this.glare && this.prepareGlare(), this.fullPageListening && this.updateClientSize(), this.addEventListeners(), this.reset(), this.updateInitialPosition()
7+
}
8+
static isSettingTrue(t) {
9+
return "" === t || !0 === t || 1 === t
10+
}
11+
getElementListener() {
12+
if (this.fullPageListening) return window.document;
13+
if ("string" == typeof this.settings["mouse-event-element"]) {
14+
const t = document.querySelector(this.settings["mouse-event-element"]);
15+
if (t) return t
16+
}
17+
return this.settings["mouse-event-element"] instanceof Node ? this.settings["mouse-event-element"] : this.element
18+
}
19+
addEventListeners() {
20+
this.onMouseEnterBind = this.onMouseEnter.bind(this), this.onMouseMoveBind = this.onMouseMove.bind(this), this.onMouseLeaveBind = this.onMouseLeave.bind(this), this.onWindowResizeBind = this.onWindowResize.bind(this), this.onDeviceOrientationBind = this.onDeviceOrientation.bind(this), this.elementListener.addEventListener("mouseenter", this.onMouseEnterBind), this.elementListener.addEventListener("mouseleave", this.onMouseLeaveBind), this.elementListener.addEventListener("mousemove", this.onMouseMoveBind), (this.glare || this.fullPageListening) && window.addEventListener("resize", this.onWindowResizeBind), this.gyroscope && window.addEventListener("deviceorientation", this.onDeviceOrientationBind)
21+
}
22+
removeEventListeners() {
23+
this.elementListener.removeEventListener("mouseenter", this.onMouseEnterBind), this.elementListener.removeEventListener("mouseleave", this.onMouseLeaveBind), this.elementListener.removeEventListener("mousemove", this.onMouseMoveBind), this.gyroscope && window.removeEventListener("deviceorientation", this.onDeviceOrientationBind), (this.glare || this.fullPageListening) && window.removeEventListener("resize", this.onWindowResizeBind)
24+
}
25+
destroy() {
26+
clearTimeout(this.transitionTimeout), null !== this.updateCall && cancelAnimationFrame(this.updateCall), this.reset(), this.removeEventListeners(), this.element.vanillaTilt = null, delete this.element.vanillaTilt, this.element = null
27+
}
28+
onDeviceOrientation(t) {
29+
if (null === t.gamma || null === t.beta) return;
30+
this.updateElementPosition(), this.gyroscopeSamples > 0 && (this.lastgammazero = this.gammazero, this.lastbetazero = this.betazero, null === this.gammazero ? (this.gammazero = t.gamma, this.betazero = t.beta) : (this.gammazero = (t.gamma + this.lastgammazero) / 2, this.betazero = (t.beta + this.lastbetazero) / 2), this.gyroscopeSamples -= 1);
31+
const e = this.settings.gyroscopeMaxAngleX - this.settings.gyroscopeMinAngleX,
32+
i = this.settings.gyroscopeMaxAngleY - this.settings.gyroscopeMinAngleY,
33+
s = e / this.width,
34+
n = i / this.height,
35+
l = (t.gamma - (this.settings.gyroscopeMinAngleX + this.gammazero)) / s,
36+
a = (t.beta - (this.settings.gyroscopeMinAngleY + this.betazero)) / n;
37+
null !== this.updateCall && cancelAnimationFrame(this.updateCall), this.event = {
38+
clientX: l + this.left,
39+
clientY: a + this.top
40+
}, this.updateCall = requestAnimationFrame(this.updateBind)
41+
}
42+
onMouseEnter() {
43+
this.updateElementPosition(), this.element.style.willChange = "transform", this.setTransition()
44+
}
45+
onMouseMove(t) {
46+
null !== this.updateCall && cancelAnimationFrame(this.updateCall), this.event = t, this.updateCall = requestAnimationFrame(this.updateBind)
47+
}
48+
onMouseLeave() {
49+
this.setTransition(), this.settings.reset && requestAnimationFrame(this.resetBind)
50+
}
51+
reset() {
52+
this.event = {
53+
clientX: this.left + this.width / 2,
54+
clientY: this.top + this.height / 2
55+
}, this.element && this.element.style && (this.element.style.transform = `perspective(${this.settings.perspective}px) ` + "rotateX(0deg) rotateY(0deg) scale3d(1, 1, 1)"), this.resetGlare()
56+
}
57+
resetGlare() {
58+
this.glare && (this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)", this.glareElement.style.opacity = "0")
59+
}
60+
updateInitialPosition() {
61+
if (0 === this.settings.startX && 0 === this.settings.startY) return;
62+
this.onMouseEnter(), this.fullPageListening ? this.event = {
63+
clientX: (this.settings.startX + this.settings.max) / (2 * this.settings.max) * this.clientWidth,
64+
clientY: (this.settings.startY + this.settings.max) / (2 * this.settings.max) * this.clientHeight
65+
} : this.event = {
66+
clientX: this.left + (this.settings.startX + this.settings.max) / (2 * this.settings.max) * this.width,
67+
clientY: this.top + (this.settings.startY + this.settings.max) / (2 * this.settings.max) * this.height
68+
};
69+
let t = this.settings.scale;
70+
this.settings.scale = 1, this.update(), this.settings.scale = t, this.resetGlare()
71+
}
72+
getValues() {
73+
let t, e;
74+
return this.fullPageListening ? (t = this.event.clientX / this.clientWidth, e = this.event.clientY / this.clientHeight) : (t = (this.event.clientX - this.left) / this.width, e = (this.event.clientY - this.top) / this.height), t = Math.min(Math.max(t, 0), 1), e = Math.min(Math.max(e, 0), 1), {
75+
tiltX: (this.reverse * (this.settings.max - t * this.settings.max * 2)).toFixed(2),
76+
tiltY: (this.reverse * (e * this.settings.max * 2 - this.settings.max)).toFixed(2),
77+
percentageX: 100 * t,
78+
percentageY: 100 * e,
79+
angle: Math.atan2(this.event.clientX - (this.left + this.width / 2), -(this.event.clientY - (this.top + this.height / 2))) * (180 / Math.PI)
80+
}
81+
}
82+
updateElementPosition() {
83+
let t = this.element.getBoundingClientRect();
84+
this.width = this.element.offsetWidth, this.height = this.element.offsetHeight, this.left = t.left, this.top = t.top
85+
}
86+
update() {
87+
let t = this.getValues();
88+
this.element.style.transform = "perspective(" + this.settings.perspective + "px) rotateX(" + ("x" === this.settings.axis ? 0 : t.tiltY) + "deg) rotateY(" + ("y" === this.settings.axis ? 0 : t.tiltX) + "deg) scale3d(" + this.settings.scale + ", " + this.settings.scale + ", " + this.settings.scale + ")", this.glare && (this.glareElement.style.transform = `rotate(${t.angle}deg) translate(-50%, -50%)`, this.glareElement.style.opacity = `${t.percentageY * this.settings["max-glare"] / 100}`), this.element.dispatchEvent(new CustomEvent("tiltChange", {
89+
detail: t
90+
})), this.updateCall = null
91+
}
92+
prepareGlare() {
93+
if (!this.glarePrerender) {
94+
const t = document.createElement("div");
95+
t.classList.add("js-tilt-glare");
96+
const e = document.createElement("div");
97+
e.classList.add("js-tilt-glare-inner"), t.appendChild(e), this.element.appendChild(t)
98+
}
99+
this.glareElementWrapper = this.element.querySelector(".js-tilt-glare"), this.glareElement = this.element.querySelector(".js-tilt-glare-inner"), this.glarePrerender || (Object.assign(this.glareElementWrapper.style, {
100+
position: "absolute",
101+
top: "0",
102+
left: "0",
103+
width: "100%",
104+
height: "100%",
105+
overflow: "hidden",
106+
"pointer-events": "none"
107+
}), Object.assign(this.glareElement.style, {
108+
position: "absolute",
109+
top: "50%",
110+
left: "50%",
111+
"pointer-events": "none",
112+
"background-image": "linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%)",
113+
transform: "rotate(180deg) translate(-50%, -50%)",
114+
"transform-origin": "0% 0%",
115+
opacity: "0"
116+
}), this.updateGlareSize())
117+
}
118+
updateGlareSize() {
119+
if (this.glare) {
120+
const t = 2 * (this.element.offsetWidth > this.element.offsetHeight ? this.element.offsetWidth : this.element.offsetHeight);
121+
Object.assign(this.glareElement.style, {
122+
width: `${t}px`,
123+
height: `${t}px`
124+
})
125+
}
126+
}
127+
updateClientSize() {
128+
this.clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth, this.clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
129+
}
130+
onWindowResize() {
131+
this.updateGlareSize(), this.updateClientSize()
132+
}
133+
setTransition() {
134+
clearTimeout(this.transitionTimeout), this.element.style.transition = this.settings.speed + "ms " + this.settings.easing, this.glare && (this.glareElement.style.transition = `opacity ${this.settings.speed}ms ${this.settings.easing}`), this.transitionTimeout = setTimeout(() => {
135+
this.element.style.transition = "", this.glare && (this.glareElement.style.transition = "")
136+
}, this.settings.speed)
137+
}
138+
extendSettings(t) {
139+
let e = {
140+
reverse: !1,
141+
max: 15,
142+
startX: 0,
143+
startY: 0,
144+
perspective: 1e3,
145+
easing: "cubic-bezier(.03,.98,.52,.99)",
146+
scale: 1,
147+
speed: 300,
148+
transition: !0,
149+
axis: null,
150+
glare: !1,
151+
"max-glare": 1,
152+
"glare-prerender": !1,
153+
"full-page-listening": !1,
154+
"mouse-event-element": null,
155+
reset: !0,
156+
gyroscope: !0,
157+
gyroscopeMinAngleX: -45,
158+
gyroscopeMaxAngleX: 45,
159+
gyroscopeMinAngleY: -45,
160+
gyroscopeMaxAngleY: 45,
161+
gyroscopeSamples: 10
162+
},
163+
i = {};
164+
for (var s in e)
165+
if (s in t) i[s] = t[s];
166+
else if (this.element.hasAttribute("data-tilt-" + s)) {
167+
let t = this.element.getAttribute("data-tilt-" + s);
168+
try {
169+
i[s] = JSON.parse(t)
170+
} catch (e) {
171+
i[s] = t
172+
}
173+
} else i[s] = e[s];
174+
return i
175+
}
176+
static init(e, i) {
177+
e instanceof Node && (e = [e]), e instanceof NodeList && (e = [].slice.call(e)), e instanceof Array && e.forEach(e => {
178+
"vanillaTilt" in e || (e.vanillaTilt = new t(e, i))
179+
})
180+
}
181+
}
182+
return "undefined" != typeof document && (window.VanillaTilt = t, t.init(document.querySelectorAll("[data-tilt]"))), t
183+
}();

0 commit comments

Comments
 (0)