Canvas landing
How do I make an canvas landing?
What is a canvas landing? How do you make a canvas landing? This script and codes were developed by Khangeldy on 09 November 2022, Wednesday.
Canvas landing - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>canvas landing</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container"> <main class="front-class"></main> <canvas id="front-id"></canvas>
</div>
<div class="assets"><img src="https://images.unsplash.com/photo-1449168013943-3a15804bb41c?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1080&fit=max&s=1958d4bfb59a246c6092ff0daabd284b" id="hero" alt="hero image"/></div> <script src="js/index.js"></script>
</body>
</html>
Canvas landing - Script Codes CSS Codes
* { box-sizing: border-box;
}
html,
body { height: 5000px;
}
.container { width: 90%; height: 300px; position: relative;
}
.front-class { position: fixed; top: 0; left: 0;
}
#front-id { background: #1c1c1c; width: 100%; height: 100%;
}
.assets { display: none;
}
.assets #hero { background-size: cover;
}
Canvas landing - Script Codes JS Codes
var canvas = document.getElementById('front-id');
var context = canvas.getContext('2d');
hero = document.getElementById('hero');
hero.addEventListener('load', function() { //context.drawImage(hero,0,0); drawImageProp(context, hero, 0, 0, canvas.width, canvas.height);
});
window.addEventListener('scroll', function() { var scrolled = window.pageYOffset; if(scrolled > 100) { hero.style.opacity = 0; }
});
function drawImageProp(ctx, img, x, y, w, h, offsetX, offsetY) { if (arguments.length === 2) { x = y = 0; w = ctx.canvas.width; h = ctx.canvas.height; } // default offset is center offsetX = typeof offsetX === "number" ? offsetX : 0.5; offsetY = typeof offsetY === "number" ? offsetY : 0.5; // keep bounds [0.0, 1.0] if (offsetX < 0) offsetX = 0; if (offsetY < 0) offsetY = 0; if (offsetX > 1) offsetX = 1; if (offsetY > 1) offsetY = 1; var iw = img.width, ih = img.height, r = Math.min(w / iw, h / ih), nw = iw * r, // new prop. width nh = ih * r, // new prop. height cx, cy, cw, ch, ar = 1; // decide which gap to fill if (nw < w) ar = w / nw; if (nh < h) ar = h / nh; nw *= ar; nh *= ar; // calc source rectangle cw = iw / (nw / w); ch = ih / (nh / h); cx = (iw - cw) * offsetX; cy = (ih - ch) * offsetY; // make sure source rectangle is valid if (cx < 0) cx = 0; if (cy < 0) cy = 0; if (cw > iw) cw = iw; if (ch > ih) ch = ih; // fill image in dest. rectangle ctx.drawImage(img, cx, cy, cw, ch, x, y, w, h);
}
Developer | Khangeldy |
Username | Khangeldy |
Uploaded | November 09, 2022 |
Rating | 3 |
Size | 3,061 Kb |
Views | 12,144 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Freecodecamp3 | 0 Kb |
Ryu Hadouken | 1,981 Kb |
Detect Facebook app in mobile devices | 1,819 Kb |
Svg | 10,044 Kb |
Css grid test | 1,683 Kb |
Tutorial greensock sprite animation | 1,854 Kb |
Trello canvas | 2,539 Kb |
Google map | 1,849 Kb |
Game in canvas | 2,977 Kb |
Shadertoy in three.js | 4,402 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Drag n Drop | Martin42 | 2,594 Kb |
Very Simple Slider | Doodlemarks | 2,682 Kb |
Subscription Newsletter - Before inlining | Bradstrong | 7,526 Kb |
Price table | Serluk | 5,928 Kb |
Simple, flat contact form | Zeaklous | 2,719 Kb |
Easing | GreenSock | 2,043 Kb |
A Pen by Markku Lehmonen | SharpDal | 7,804 Kb |
Menu | Vivi_Lai | 1,210 Kb |
Nice responsive team page | Infomiho | 3,139 Kb |
Opening Reveal Modal On Document Ready | Winghouchan | 1,787 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!