Canvas landing

Developer
Size
3,061 Kb
Views
12,144

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 Previews

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&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;w=1080&amp;fit=max&amp;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);
}
Canvas landing - Script Codes
Canvas landing - Script Codes
Home Page Home
Developer Khangeldy
Username Khangeldy
Uploaded November 09, 2022
Rating 3
Size 3,061 Kb
Views 12,144
Do you need developer help for Canvas landing?

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!

Khangeldy (Khangeldy) Script Codes
Create amazing SEO content with AI!

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!