- šÆš“Jordan Rajab Natshah Jordan
Having a hint of a good solution with "Using
attr
to setcss
variable inline"Working on an implementation for this in š Fix Layout Builder section rendering original Background Image when no background options, no image styles, or lazy loading are applied Active
Example of a Custom responsive Ration developed Bootstrap Utility Classes
- Bootstrap Ratio Utilities ( under development)
Override aspect ratios array to add more ratios.
// Override bootstrap 5 variables // ---------------------------------------------------------------- // See more about override Bootstrap 5 variables here: // https://getbootstrap.com/docs/5.0/customize/sass // https://github.com/twbs/bootstrap/blob/v5.2.3/scss/_variables.scss // Override aspect ratios array to add more ratios. $aspect-ratios: ( "1x1": 100%, "2x1": calc(1 / 2 * 100%), "3x1": calc(1 / 3 * 100%), "4x1": calc(1 / 4 * 100%), "4x3": calc(3 / 4 * 100%), "16x9": calc(9 / 16 * 100%), "21x9": calc(9 / 21 * 100%), );
- Assigned to Rajab Natshah
- šÆš“Jordan Rajab Natshah Jordanā Released Bootstrap Ratio Utilities 1.0.2
https://github.com/Vardot/bootstrap-ratio-utilities#readme
Having Two Bootstrap Ratio Utilities
Responsive ratio utility
Ratio Utility with responsive options, which needed for switching ratios for media breakpoints.
Adds (
-sm
,-md
,-lg
,-xl
,-xxl
) to ratio classes to change the ratio for that brackpoint.
Use the normal ration classes for mobiles which less than -smFlip Ratio Utility
Flip Ratio Utility, which needed for flipping ratios for media breakpoints.
Adds (
-flip-xs
,-flip-sm
,-flip-md
,-flip-lg
,-flip-xl
,-flip-xxl
) to ratio classes to change the ratio for that brackpoint
Use the-flip-xs
ratio classes for mobiles which less than-flip-sm
or-sm
in case of using both ratio utilities at the same timeš Add Dynamic Responsive Image (or drimage) module to Varbase Media Fixed
š Add the Bootstrap Ratio Utilities package and import the Responsive Ratio Utility in the Base Bootstrap SCSS Active
š Add the Responsive Ratio Utility provided by the Bootstrap Ratio Utilities for media video displays with cover images Active
š Fix Layout Builder section rendering original Background Image when no background options, no image styles, or lazy loading are applied ActiveHaving a hint of a good solution with "Using
attr
to setcss
variable inline"In the buildBackgroundMediaImage
The
$style = 'background-image: url(' . $background_url . ');';
could be manged with media selection for each breakpoints- xs
$style .= '@media (max-width: 576px) {'; $style .= ' background-image: attr(data-bs-xs-bg-image);'; $style .= '}';
- sm
$style .= '@media (min-width: 576px) {'; $style .= ' background-image: attr(data-bs-sm-bg-image);'; $style .= '}';
- md
$style .= '@media (min-width: 768px) {'; $style .= ' background-image: attr(data-bs-md-bg-image);'; $style .= '}';
- lg
$style .= '@media (min-width: 992px) {'; $style .= ' background-image: attr(data-bs-lg-bg-image);'; $style .= '}';
- xl
$style .= '@media (min-width: 1200px) {'; $style .= ' background-image: attr(data-bs-xl-bg-image);'; $style .= '}';
- xxl
$style .= '@media (min-width: 1400px) {; $style .= ' background-image: attr(data-bs-xxl-bg-image);'; $style .= '}';
And add the
"data-bs-xs-bg-image"
,"data-bs-sm-bg-image"
,"data-bs-md-bg-image"
,"data-bs-lg-bg-image"
,"data-bs-xl-bg-image"
,"data-bs-xxl-bg-image"
data attributes to the section main element ( template, by passing the selected image style for each breakpoints).---
It is possible to add an integration with Drimage using this way tooThis could be integrated to work with any UI Framework or any set of configured breakpoints
- xs
- š®š¹Italy finex
Hi, I'm also interested on a solution to enable different crop types based on screen size/orientation.
- š®š¹Italy finex
Hi, I'm experimenting with an hardcoded JS workaround. I've created two "background" crop types (landscape and portrait). If on the field formatter one of those preset is enabled, then on the JS i simply check the window size and eventually swap the crop type.
This is a simple example code I've put on drimage.js on
Drupal.drimage.renderEl
before setting theimgUrl
variable:if (iwc == "crop_landscape_background" || iwc == "crop_portrait_background"){ if (window.innerHeight < window.innerWidth) { iwc = 'crop_landscape_background'; } if (window.innerHeight > window.innerWidth) { iwc = 'crop_portrait_background'; } }
This approach is quite simple and it only needs a "portrait crop style" setting on the field formatter in order to be more dynamic instead of hardcoded.
What do you think? It could be an easy solution until a more flexible solution will be implemented. Let me know.
- Status changed to Closed: won't fix
6 months ago 10:20am 19 June 2024 - š§šŖBelgium weseze
The field_widget / field_formatter implementation is in my opinion the only correct way forward for this.
I will close this issue since there is lack of development on this feature. (and I personally do not have a need for it)
If this changes, do not hesitate to ask my to reopen this issue, or start a new one.
This could also be done in another contrib module. - šÆš“Jordan Rajab Natshah Jordan
Noted;
Thank you, Wesley, your direction is taken. ( it is a field formatter setting for breakpoints )
and thanks a lot for the idea of Drimage, BBC, CNN, and more are using this ideaMy only wish is that if Drupal.org allow us to have a clean fork ref. like what we have github.com or gitlab.com
to keep the forks related, as a child change of the original project, which could still upstream or merge pull requests, from forks or originalMoving our focus for more improvements in Drimage Improved ā
āØ Add Responsive Aspect Ratios Active