Fullscreen image in Canvas
How do I make an fullscreen image in canvas?
In a project, I needed to draw image fullscreen in canvas.. What is a fullscreen image in canvas? How do you make a fullscreen image in canvas? This script and codes were developed by Chrysto on 16 July 2022, Saturday.
Fullscreen image in Canvas - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Fullscreen image in Canvas</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="canvas__holder"> <canvas id="image__canvas"> </canvas>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Fullscreen image in Canvas - Script Codes CSS Codes
body, html, div, canvas { margin: 0; padding: 0; outline: none; box-sizing: border-box;
}
Fullscreen image in Canvas - Script Codes JS Codes
$(function() { var $window = $(window), $canvasHolder = $(".canvas__holder"), $canvas = $("#image__canvas"), canvas = $canvas.get(0), canvasContext = canvas.getContext("2d") var winWidth, winHeight, winRatio, imgWidth, imgHeight, imgRatio, canvasInited; var img; var $img = $("<img />", { "src": "http://ivayloyovchev.com/pulsepro/data/img/gallery/personal/IMG_0010_.jpg" }).load(function() { img = $img.get(0); imgWidth = img.width; imgHeight = img.height; imgRatio = imgWidth / imgHeight; canvasInited = true; resizeCanvas(); }); $window.on("resize", onResize); $window.trigger("resize"); function onResize() { winWidth = $window.width(); winHeight = $window.height(); winRatio = winWidth / winHeight; $canvas.attr({ "width": winWidth + "px", "height": winHeight + "px" }); $canvasHolder.add($canvas).css({ "width": winWidth + "px", "height": winHeight + "px" }); if (canvasInited) { resizeCanvas(); } } function resizeCanvas() { var newWidth = winWidth, newHeight = winHeight, newX = 0, newY = 0; if (winRatio > imgRatio) { newHeight = Math.round(winWidth / imgRatio); newY = (winHeight - newHeight) / 2; } else { newWidth = Math.round(winHeight * imgRatio); newX = (winWidth - newWidth) / 2; } canvasContext.drawImage(img, newX, newY, newWidth, newHeight); }
});
Developer | Chrysto |
Username | bassta |
Uploaded | July 16, 2022 |
Rating | 3 |
Size | 2,268 Kb |
Views | 30,360 |
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 |
TweenMax text - changing slogans | 2,333 Kb |
Medium.com style header effect | 2,828 Kb |
Click outside element | 1,993 Kb |
GSAP Parallax | 2,513 Kb |
Simple GSAP Slider | 2,839 Kb |
TweenLite staggerTo | 2,495 Kb |
A Pen by Chrysto | 2,057 Kb |
Fullscreen slides with TweenLite, CSSPlugin and ScrollToPlugin | 4,226 Kb |
Fullscreen Parallax | 3,313 Kb |
Single page website | 2,688 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 |
Webkit decolorize | Fivera | 1,675 Kb |
Improve | Gavra | 1,652 Kb |
React Vote Component | Souporserious | 5,465 Kb |
WRENCH - STAFF | Lolita-adams | 1,608 Kb |
Slider css only | Armandobau | 2,161 Kb |
Typefaces with descriptions | Megandoty | 2,944 Kb |
Horizontal scroll fixed element | HerrSerker | 0 Kb |
Personal Website Redesign v2.0 | DevItWithDavid | 5,168 Kb |
Sass Get Function | Lukewatts | 2,155 Kb |
Search field | Jamesbarnett | 2,100 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!