responsive

This commit is contained in:
2021-12-08 19:25:03 -05:00
parent d82aeb744b
commit e86f1afb2f
3 changed files with 228 additions and 147 deletions

View File

@@ -1,5 +1,5 @@
* { * {
box-sizing: border-box; box-sizing: border-box;
} }
body { body {
@@ -12,40 +12,47 @@ body {
} }
.background { .background {
background-color: #0e0e0e; background-color: #0e0e0e;
background-image: repeating-linear-gradient(135deg, #000, #19191a 1%, transparent 1.5%, transparent 50% ); background-image: repeating-linear-gradient(
135deg,
#000,
#19191a 1%,
transparent 1.5%,
transparent 50%
);
background-size: 100px 100px; background-size: 100px 100px;
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
animation: fade-in 2500ms ease-out forwards 1s; animation: fade-in 1750ms ease-out forwards;
opacity: 0; opacity: 0;
} }
.card { .card {
display: block; display: block;
position: relative; position: relative;
width: 420px; max-width: 420px;
width: 80%;
height: 260px; height: 260px;
color: #fff; color: #fff;
flex: none; flex: none;
perspective: 1000px; perspective: 1000px;
} }
.card__figure { .card__figure {
margin: 0; margin: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
display: block; display: block;
position: relative; position: relative;
background: #111; background: #111;
border-radius: 2px; border-radius: 3px;
} }
.card__figure::before { .card__figure::before {
content: ''; content: "";
position: absolute; position: absolute;
width: calc(100% - 14px); width: calc(100% - 14px);
height: calc(100% - 14px); height: calc(100% - 14px);
@@ -58,26 +65,32 @@ body {
} }
.card__deco { .card__deco {
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
pointer-events: none; pointer-events: none;
border-radius: 3px;
} }
.card__deco--shine div { .card__deco--shine div {
position: absolute; position: absolute;
width: 200%; width: 200%;
height: 200%; height: 200%;
top: -50%; top: -50%;
left: -50%; left: -50%;
background-image: linear-gradient(45deg, rgba(0, 0, 0, 0.9) 0%, rgba(200, 200, 200, 0.05) 50%, transparent 100%); background-image: linear-gradient(
45deg,
rgba(0, 0, 0, 0.9) 0%,
rgba(200, 200, 200, 0.05) 50%,
transparent 100%
);
} }
figcaption { figcaption {
height: 100%; height: 100%;
padding: 25px; padding: 25px;
color: #eee; color: #eee;
font-family: Avenir; font-family: Avenir;
@@ -94,17 +107,42 @@ h1 {
} }
p { p {
margin: 0; margin: 0;
font-weight: 900; font-weight: 900;
} }
@keyframes fade-in { @keyframes fade-in {
0% { 0% {
opacity: 0; opacity: 0;
} }
100% { 100% {
opacity: 1; opacity: 1;
} }
} }
@media screen and (max-width: 430px) {
.card {
height: 450px;
}
}
@media screen and (max-width: 380px) {
h1 {
font-size: 2.8rem;
line-height: 2.8rem;
}
}
@media screen and (max-width: 330px) {
h1 {
font-size: 2rem;
line-height: 2rem;
}
}
@media screen and (max-width: 250px) {
h1 {
font-size: 1.3rem;
line-height: 1.3rem;
}
}

View File

@@ -2,9 +2,9 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Travis Heinström</title> <title>Travis Heinström</title>
<meta name="description" content="" /> <meta name="description" content="" />
<!-- Needs Favicon --> <!-- Needs Favicon -->
@@ -12,30 +12,26 @@
<link rel="stylesheet" type="text/css" href="./css/style.css" /> <link rel="stylesheet" type="text/css" href="./css/style.css" />
</head> </head>
<body> <body>
<div class="background"></div> <div class="background"></div>
<div class="card">
<main> <figure class="card__figure">
<section class="content"> <div class="card__deco card__deco--shine"><div></div></div>
<div class="card"> <figcaption>
<figure class="card__figure"> <h1>
<div class="card__deco card__deco--shine"><div></div></div> Travis <br />
<figcaption> Heinström
<h1>Travis <br/> Heinström</h1> </h1>
<p>Things Here<br/>Things Here - Things here</p> <p>Things Here<br />Things Here - Things here</p>
</figcaption> </figcaption>
</figure> </figure>
</div> </div>
</section>
</main>
<script src="./js/anime.min.js"></script> <script src="./js/anime.min.js"></script>
<script src="./js/main.js"></script> <script src="./js/main.js"></script>
<script> <script>
(function() { (function () {
new TiltFx(document.querySelector('.card', {})) new TiltFx(document.querySelector(".card", {}));
})() })();
</script> </script>
</body> </body>
</html> </html>

View File

@@ -1,12 +1,10 @@
(function (window) {
;(function(window) { "use strict";
'use strict';
// Helper vars and functions. // Helper vars and functions.
function extend( a, b ) { function extend(a, b) {
for( var key in b ) { for (var key in b) {
if( b.hasOwnProperty( key ) ) { if (b.hasOwnProperty(key)) {
a[key] = b[key]; a[key] = b[key];
} }
} }
@@ -14,17 +12,23 @@
} }
function getMousePos(e) { function getMousePos(e) {
var posx = 0, posy = 0; var posx = 0,
posy = 0;
if (!e) var e = window.event; if (!e) var e = window.event;
if (e.pageX || e.pageY) { if (e.pageX || e.pageY) {
posx = e.pageX; posx = e.pageX;
posy = e.pageY; posy = e.pageY;
} else if (e.clientX || e.clientY) {
posx =
e.clientX +
document.body.scrollLeft +
document.documentElement.scrollLeft;
posy =
e.clientY +
document.body.scrollTop +
document.documentElement.scrollTop;
} }
else if (e.clientX || e.clientY) { return { x: posx, y: posy };
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
return { x : posx, y : posy }
} }
/** /**
@@ -40,61 +44,76 @@
TiltFx.prototype.options = { TiltFx.prototype.options = {
movement: { movement: {
imgWrapper : { wrapper: {
translation : {x: 0, y: 0, z: 0}, translation: { x: 0, y: 0, z: 0 },
rotation : {x: -5, y: 5, z: 0}, rotation: { x: -5, y: 5, z: 0 },
reverseAnimation : { reverseAnimation: {
duration : 1200, duration: 1200,
easing : 'easeOutElastic', easing: "easeOutElastic",
elasticity : 600 elasticity: 600,
} },
}, },
shine : { shine: {
translation : {x: 50, y: 50, z: 0}, translation: { x: 50, y: 50, z: 0 },
reverseAnimation : { reverseAnimation: {
duration : 1200, duration: 1200,
easing : 'easeOutElastic', easing: "easeOutElastic",
elasticity: 600 elasticity: 600,
} },
} },
} },
}; };
/** /**
* Init. * Init.
*/ */
TiltFx.prototype._init = function() { TiltFx.prototype._init = function () {
this.DOM.animatable = {}; this.DOM.animatable = {};
this.DOM.animatable.imgWrapper = this.DOM.el.querySelector('.card__figure'); this.DOM.animatable.wrapper = this.DOM.el.querySelector(".card__figure");
this.DOM.animatable.shine = this.DOM.el.querySelector('.card__deco--shine > div'); this.DOM.animatable.shine = this.DOM.el.querySelector(
".card__deco--shine > div"
);
this._initEvents(); this._initEvents();
}; };
/** /**
* Init/Bind events. * Init/Bind events.
*/ */
TiltFx.prototype._initEvents = function() { TiltFx.prototype._initEvents = function () {
var self = this; var self = this;
this.mouseenterFn = function() { this.mouseenterFn = function () {
for(var key in self.DOM.animatable) { for (var key in self.DOM.animatable) {
anime.remove(self.DOM.animatable[key]); anime.remove(self.DOM.animatable[key]);
} }
}; };
this.mousemoveFn = function(ev) { this.mousemoveFn = function (ev) {
requestAnimationFrame(function() { self._layout(ev); }); requestAnimationFrame(function () {
self._layout(ev);
});
}; };
this.mouseleaveFn = function(ev) { this.mouseleaveFn = function (ev) {
requestAnimationFrame(function() { requestAnimationFrame(function () {
for(var key in self.DOM.animatable) { for (var key in self.DOM.animatable) {
if( self.options.movement[key] == undefined ) {continue;} if (self.options.movement[key] == undefined) {
continue;
}
anime({ anime({
targets: self.DOM.animatable[key], targets: self.DOM.animatable[key],
duration: self.options.movement[key].reverseAnimation != undefined ? self.options.movement[key].reverseAnimation.duration || 0 : 1, duration:
easing: self.options.movement[key].reverseAnimation != undefined ? self.options.movement[key].reverseAnimation.easing || 'linear' : 'linear', self.options.movement[key].reverseAnimation != undefined
elasticity: self.options.movement[key].reverseAnimation != undefined ? self.options.movement[key].reverseAnimation.elasticity || null : null, ? self.options.movement[key].reverseAnimation.duration || 0
: 1,
easing:
self.options.movement[key].reverseAnimation != undefined
? self.options.movement[key].reverseAnimation.easing || "linear"
: "linear",
elasticity:
self.options.movement[key].reverseAnimation != undefined
? self.options.movement[key].reverseAnimation.elasticity || null
: null,
scaleX: 1, scaleX: 1,
scaleY: 1, scaleY: 1,
scaleZ: 1, scaleZ: 1,
@@ -103,64 +122,92 @@
translateZ: 0, translateZ: 0,
rotateX: 0, rotateX: 0,
rotateY: 0, rotateY: 0,
rotateZ: 0 rotateZ: 0,
}); });
} }
}); });
}; };
this.DOM.el.addEventListener('mousemove', this.mousemoveFn); this.DOM.el.addEventListener("mousemove", this.mousemoveFn);
this.DOM.el.addEventListener('mouseleave', this.mouseleaveFn); this.DOM.el.addEventListener("mouseleave", this.mouseleaveFn);
this.DOM.el.addEventListener('mouseenter', this.mouseenterFn); this.DOM.el.addEventListener("mouseenter", this.mouseenterFn);
}; };
TiltFx.prototype._layout = function(ev) { TiltFx.prototype._layout = function (ev) {
// Mouse position relative to the document. // Mouse position relative to the document.
var mousepos = getMousePos(ev), var mousepos = getMousePos(ev),
// Document scrolls. // Document scrolls.
docScrolls = {left : document.body.scrollLeft + document.documentElement.scrollLeft, top : document.body.scrollTop + document.documentElement.scrollTop}, docScrolls = {
left: document.body.scrollLeft + document.documentElement.scrollLeft,
top: document.body.scrollTop + document.documentElement.scrollTop,
},
bounds = this.DOM.el.getBoundingClientRect(), bounds = this.DOM.el.getBoundingClientRect(),
// Mouse position relative to the main element (this.DOM.el). // Mouse position relative to the main element (this.DOM.el).
relmousepos = { x : mousepos.x - bounds.left - docScrolls.left, y : mousepos.y - bounds.top - docScrolls.top }; relmousepos = {
x: mousepos.x - bounds.left - docScrolls.left,
y: mousepos.y - bounds.top - docScrolls.top,
};
// Movement settings for the animatable elements. // Movement settings for the animatable elements.
for(var key in this.DOM.animatable) { for (var key in this.DOM.animatable) {
if( this.DOM.animatable[key] == undefined || this.options.movement[key] == undefined ) { if (
this.DOM.animatable[key] == undefined ||
this.options.movement[key] == undefined
) {
continue; continue;
} }
var t = this.options.movement[key] != undefined ? this.options.movement[key].translation || {x:0,y:0,z:0} : {x:0,y:0,z:0}, var t =
r = this.options.movement[key] != undefined ? this.options.movement[key].rotation || {x:0,y:0,z:0} : {x:0,y:0,z:0}, this.options.movement[key] != undefined
? this.options.movement[key].translation || { x: 0, y: 0, z: 0 }
: { x: 0, y: 0, z: 0 },
r =
this.options.movement[key] != undefined
? this.options.movement[key].rotation || { x: 0, y: 0, z: 0 }
: { x: 0, y: 0, z: 0 },
setRange = function (obj) { setRange = function (obj) {
for(var k in obj) { for (var k in obj) {
if( obj[k] == undefined ) { if (obj[k] == undefined) {
obj[k] = [0,0]; obj[k] = [0, 0];
} } else if (typeof obj[k] === "number") {
else if( typeof obj[k] === 'number' ) { obj[k] = [-1 * obj[k], obj[k]];
obj[k] = [-1*obj[k],obj[k]];
} }
} }
}; };
setRange(t); setRange(t);
setRange(r); setRange(r);
var transforms = { var transforms = {
translation : { translation: {
x: (t.x[1]-t.x[0])/bounds.width*relmousepos.x + t.x[0], x: ((t.x[1] - t.x[0]) / bounds.width) * relmousepos.x + t.x[0],
y: (t.y[1]-t.y[0])/bounds.height*relmousepos.y + t.y[0], y: ((t.y[1] - t.y[0]) / bounds.height) * relmousepos.y + t.y[0],
z: (t.z[1]-t.z[0])/bounds.height*relmousepos.y + t.z[0], z: ((t.z[1] - t.z[0]) / bounds.height) * relmousepos.y + t.z[0],
},
rotation: {
x: ((r.x[1] - r.x[0]) / bounds.height) * relmousepos.y + r.x[0],
y: ((r.y[1] - r.y[0]) / bounds.width) * relmousepos.x + r.y[0],
z: ((r.z[1] - r.z[0]) / bounds.width) * relmousepos.x + r.z[0],
}, },
rotation : {
x: (r.x[1]-r.x[0])/bounds.height*relmousepos.y + r.x[0],
y: (r.y[1]-r.y[0])/bounds.width*relmousepos.x + r.y[0],
z: (r.z[1]-r.z[0])/bounds.width*relmousepos.x + r.z[0]
}
}; };
this.DOM.animatable[key].style.WebkitTransform = this.DOM.animatable[key].style.transform = 'translateX(' + transforms.translation.x + 'px) translateY(' + transforms.translation.y + 'px) translateZ(' + transforms.translation.z + 'px) rotateX(' + transforms.rotation.x + 'deg) rotateY(' + transforms.rotation.y + 'deg) rotateZ(' + transforms.rotation.z + 'deg)'; this.DOM.animatable[key].style.WebkitTransform = this.DOM.animatable[
key
].style.transform =
"translateX(" +
transforms.translation.x +
"px) translateY(" +
transforms.translation.y +
"px) translateZ(" +
transforms.translation.z +
"px) rotateX(" +
transforms.rotation.x +
"deg) rotateY(" +
transforms.rotation.y +
"deg) rotateZ(" +
transforms.rotation.z +
"deg)";
} }
}; };
window.TiltFx = TiltFx; window.TiltFx = TiltFx;
})(window);
})(window);