Responsive focuspoint on image with object-position
How do I make an responsive focuspoint on image with object-position?
A simple image focuspoint implementation based on the new object-position and object-fit css properties.. What is a responsive focuspoint on image with object-position? How do you make a responsive focuspoint on image with object-position? This script and codes were developed by Karsten Buckstegge on 10 September 2022, Saturday.
Responsive focuspoint on image with object-position - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Responsive focuspoint on image with object-position</title> <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> <figure class="focus__area"> <div class="focus__picker"> <img class="focus__picker__image" src="http://www.ucreative.com/wp-content/uploads/2014/11/Landscape-Photography-Banner1.jpg" alt="" /> <span class="focus__picker__indicator"></span> </div> <p class="focus__area__info">⬅ choose<br /> focuspoint<br />here!</p> <p class="media__info">Use bigger screen to pick a focus point!</p> <img class="focus__image" src="http://www.ucreative.com/wp-content/uploads/2014/11/Landscape-Photography-Banner1.jpg" alt="" /> <figcaption class="focus__caption"> focus-point: <span></span> </figcaption>
</figure> <script src="js/index.js"></script>
</body>
</html>
Responsive focuspoint on image with object-position - Script Codes CSS Codes
html, body { height: 100%;
}
.focus__area__info,
.media__info { position: absolute; color: #fff; top: 0; left: 22%; margin: 0; padding: 20px; background: rgba(0, 120, 100, 0.7);
}
.media__info { display: none;
}
.focus__caption { position: absolute; right: 20px; bottom: 20px; padding: 20px; background: rgba(0, 120, 100, 0.7); color: #fff;
}
.focus__area { position: relative; margin: 0; padding: 0; width: 100%; height: 100%;
}
.focus__picker { position: absolute; width: 20%; border: 4px solid black; cursor: crosshair;
}
.focus__picker__image { width: 100%;
}
.focus__picker__indicator { position: absolute; width: 10px; height: 10px; background: rgba(255, 255, 255, 0.7); border-radius: 50%; left: calc(50% - 5px); top: calc(50% - 5px);
}
.focus__image { width: 100%; height: 100%; object-fit: none; object-position: top 50% left 50%;
}
@media (max-width: 700px), (max-height: 300px) { .focus__caption, .focus__area__info, .focus__picker { display: none; } .media__info { display: block; left: 0; margin: 0 2%; }
}
Responsive focuspoint on image with object-position - Script Codes JS Codes
'use strict';
var focusArea = document.querySelector('.focus__area');
var focusPicker = focusArea.querySelector('.focus__picker');
var focusPickerIndicator = focusArea.querySelector('.focus__picker__indicator');
var focusImage = focusArea.querySelector('.focus__image');
var focusCaptionSpan = focusArea.querySelector('.focus__caption span');
var setFocusPoint = function setFocusPoint(e) { var focusOffset = [e.offsetY, e.offsetX]; var imageSize = [focusPicker.clientHeight, focusPicker.clientWidth]; var focusPointY = (focusOffset[0] / imageSize[0] * 100).toFixed(1); var focusPointX = (focusOffset[1] / imageSize[1] * 100).toFixed(1); focusCaptionSpan.innerHTML = 'Y: ' + focusPointY + ', X: ' + focusPointX; focusImage.style.objectPosition = 'top ' + focusPointY + '% left ' + focusPointX + '%'; focusPickerIndicator.style.top = 'calc(' + focusPointY + '% - 5px)'; focusPickerIndicator.style.left = 'calc(' + focusPointX + '% - 5px)';
};
focusPicker.addEventListener('click', setFocusPoint);
Developer | Karsten Buckstegge |
Username | MrBambule |
Uploaded | September 10, 2022 |
Rating | 4 |
Size | 3,707 Kb |
Views | 42,504 |
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 |
CSS3 Hover Button | 3,717 Kb |
A Pen by Karsten Buckstegge | 3,521 Kb |
The wheel of social fortune | 6,570 Kb |
Simple React Slider | 4,975 Kb |
The wheel of social | 4,072 Kb |
Dropdown Menu Animation | 3,411 Kb |
Even More Brokener TV | 2,571 Kb |
Freddy the Fly | 4,238 Kb |
Base64 SVG Me | 44,786 Kb |
Broken TV | 2,456 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 |
GLSL Hills | Ykob | 6,991 Kb |
A Pen by Brendan Skousen | Bskousen | 2,954 Kb |
A Pen by Tosh | Panev | 2,586 Kb |
Template | Indra_z85 | 2,323 Kb |
Halo 5 REQ Guide Bookmarklet | Cwacht | 3,993 Kb |
Drawing a Terminal with CSS | Lachlanjc | 3,185 Kb |
Touch Carousel - last, no gaps. | Berkin | 4,332 Kb |
A Pen by Alex Edwards | Exards | 8,218 Kb |
Awesome | Samarthpd | 2,901 Kb |
Revolving Text Landing Page Trial | TimRuby | 2,976 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!