mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
fix image aspect ratio when scaling, again
also when image hasn't loaded yet to prevent scroll position jumps
This commit is contained in:
parent
c73bf96a58
commit
1ec2543467
@ -27,10 +27,23 @@
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.message-container img {
|
||||
max-width: 100%;
|
||||
height: 100%;
|
||||
.message-container a {
|
||||
display: block;
|
||||
position: relative;
|
||||
max-width: 100%;
|
||||
/* width and padding-top set inline to maintain aspect ratio,
|
||||
replace with css aspect-ratio once supported */
|
||||
}
|
||||
|
||||
.message-container img {
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.TextMessageView {
|
||||
|
@ -2,12 +2,26 @@ import {TemplateView} from "../../../general/TemplateView.js";
|
||||
|
||||
export class ImageView extends TemplateView {
|
||||
render(t, vm) {
|
||||
// replace with css aspect-ratio once supported
|
||||
const heightRatioPercent = (vm.thumbnailHeight / vm.thumbnailWidth) * 100;
|
||||
const image = t.img({
|
||||
src: vm.thumbnailUrl,
|
||||
width: vm.thumbnailWidth,
|
||||
height: vm.thumbnailHeight,
|
||||
loading: "lazy",
|
||||
alt: vm.label,
|
||||
});
|
||||
const linkContainer = t.a({
|
||||
href: vm.url,
|
||||
target: "_blank",
|
||||
style: `padding-top: ${heightRatioPercent}%; width: ${vm.thumbnailWidth}px;`
|
||||
}, image);
|
||||
|
||||
return t.li(
|
||||
{className: {"TextMessageView": true, own: vm.isOwn, pending: vm.isPending}},
|
||||
t.div({className: "message-container"}, [
|
||||
t.div({className: "sender"}, vm => vm.isContinuation ? "" : vm.sender),
|
||||
t.div(t.a({href: vm.url, target: "_blank"},
|
||||
t.img({src: vm.thumbnailUrl, width: vm.thumbnailWidth, height: vm.thumbnailHeight, loading: "lazy", alt: vm.label}))),
|
||||
t.div(linkContainer),
|
||||
t.p(t.time(vm.date + " " + vm.time)),
|
||||
])
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user