Hello,
I'm having a problem with the "prop" value, which is causing a bug in my Lightbox.
This lightbox is built with a container layer to add margin and darken the background, and inside, a layer that contains the image.
I'd like this image to be displayed at a maximum of 100% of the parent at its largest width, while respecting its aspect ratio.
First of all, the maxwidth and maxheight parameters don't work with percentages, which doesn't suit me (if the image is smaller than its context, then it's zoomed in, which I don't want).
But I especially have a problem with "prop"from what I've tested:
- If the image size is not defined, it will be displayed at its original size, regardless of the context.
- If width and height are set to 100%, the image is displayed at 100% of the context (after deducting the margins defined in the container), but this logically breaks the aspect ratio.
- If the width or height is set to 100% and the other value is set to prop, then the aspect ratio is respected and the 100% value respects the context and its margins, but the other axis set to prop no longer respects the context and may go outside the margins and the viewport...
As a result, in my example, if I want to display a horizontal image on a vertical screen, the image is taken out of the screen, and if I invert height and width, then it would be the vertical images that would be taken out of the display on a horizontal screen.
In short, what I'd like is the equivalent of the "object-fit: contain;" function in css:
Do you have any ideas on how to get round this problem?
Here's my code:
<!-- Lightbox -->
<layer
name="boxbg"
type="container"
visible="false"
width="100%"
height="100%"
keep="true"
bgcolor="0x000000"
bgalpha="0.0"
bgblur="0"
childmargin="30 30 120"
scalechildren="true"
>
<layer
name="boximg"
type="image"
url=""
align="center"
height="100%"
width="prop"
alpha="0"
onclick="close_lightbox();"
/>
</layer>
<action name="open_lightbox">
set(layer[boxbg].visible, true);
set(layer[boximg].url, get(layer[boximg].img_url));
tween(layer[boxbg].bgalpha, 0.6, 0.3);
tween(layer[boxbg].bgblur, 6, 0.3);
tween(layer[boximg].alpha, 1, 0.3);
</action>
<action name="close_lightbox">
tween(layer[boxbg].bgalpha, 0, 0.3);
tween(layer[boxbg].bgblur, 0, 0.3);
tween(layer[boximg].alpha, 0, 0.3);
delayedcall(0.3, set(layer[boxbg].visible, false));
</action>
<!-- // Lightbox -->
<hotspot name="test" style="skin_imagestyle" ath="-83.05398201806679" atv="10.8840575489464825" title="test" distorted="false" onclick="set(layer[boximg].img_url, 'test.png'); open_lightbox();" />
Display More
Thank you