Object-fit polyfill
How do I make an object-fit polyfill?
What is a object-fit polyfill? How do you make a object-fit polyfill? This script and codes were developed by Jonathan Neal on 30 August 2022, Tuesday.
Object-fit polyfill - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>object-fit polyfill</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <img src="https://placehold.it/1080x200" data-object-fit="cover">
<img src="https://placehold.it/1080x200" data-object-fit="contain"> <script src="js/index.js"></script>
</body>
</html>
Object-fit polyfill - Script Codes CSS Codes
img { box-shadow: 0 0 0 1px; height: 200px; width: 200px;
}
img[data-object-fit="contain"] { object-fit: contain;
}
img[data-object-fit="cover"] { object-fit: cover;
}
Object-fit polyfill - Script Codes JS Codes
if ('objectFit' in document.documentElement.style === false) { document.addEventListener('DOMContentLoaded', function () { Array.prototype.forEach.call(document.querySelectorAll('img[data-object-fit]'), function (image) { (image.runtimeStyle || image.style).background = 'url("' + image.src + '") no-repeat 50%/' + (image.currentStyle ? image.currentStyle['object-fit'] : image.getAttribute('data-object-fit')); image.src = 'data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'' + image.width + '\' height=\'' + image.height + '\'%3E%3C/svg%3E'; }); });
}
Developer | Jonathan Neal |
Username | jonneal |
Uploaded | August 30, 2022 |
Rating | 4.5 |
Size | 1,919 Kb |
Views | 44,528 |
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 |
SVG for Everybody | 3,207 Kb |
Autohide Bars | 2,570 Kb |
Yelp Ratings SVG | 2,284 Kb |
Aim-Aware Menus | 2,950 Kb |
Decorative Text Underline | 2,713 Kb |
PostCSS Write SVG Example | 1,554 Kb |
OkayNav in VanillaJS | 4,147 Kb |
SVG with and without viewBox | 2,141 Kb |
Preload Example | 2,335 Kb |
Responsive Text Sizes | 2,269 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 |
Collapsing Widget | Er40 | 4,279 Kb |
Angular-HAML | Cwacht | 2,022 Kb |
Two Element Typeface | Chrisota | 4,942 Kb |
Simple checkbox style | Vncnz | 2,628 Kb |
Gradient-ui-button-mark-fx | Tabspace | 1,881 Kb |
404 Error Page | WebSonick | 3,203 Kb |
A simple log in form made with css | Mayurelbhar | 2,160 Kb |
Transitioning application screens with semantically named classes | Djgrant | 3,697 Kb |
Adding Items | Valhead | 4,008 Kb |
How to add Css Fold Notes In Blogger By Askwithloud.com | Askwithloud | 2,280 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!