Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intro image scaling if used in compound content types #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

otacke
Copy link
Contributor

@otacke otacke commented Mar 1, 2020

When using QS in compound content types (in Column in particular),
the intro div may not have been rendered when determining its
width. In consequence, instead of scaling the intro image to full
width, it would be displayed in its natural dimensions in Column.

This pull request fixes this behavior and the intro image will scale
properly in Column as well.

When using QS in compount content types (in Column in particular),
the intro div may not have been rendered when determining its
width. In consequence, instead of scaling the intro image to full
width, it would be displayed in its natural dimensions in Column.

This pull request fixes this behavior and the intro image will scale
properly in Column as well.
@ilukanets
Copy link

We have the same issue with intro image on our platform. It's really annoying and we have a lot of complaints from our users. Problem appears more often if image has large size and it takes more time to load it.

@otacke I'm not sure setTimeout is the best solution, but if it works... As an alternative I suggest an image could be created with JS and styles to be attached on image load event.

var bgImg = params.introPage.backgroundImage;
var bgImhPath = H5P.getPath(bgImg.path, contentId);
var bgImgRatio = (bgImg.height / bgImg.width);
var image = new Image();
        
image.onload = function() {
   $intro.css({
     background: '#fff url("' + bgImgPath + '") no-repeat 50% 50%',
     backgroundSize: 'auto 100%',
     minHeight: bgImgRatio * +window.getComputedStyle($intro[0]).width.replace('px','')
   });
}

image.src = bgImgPath;

@otacke
Copy link
Contributor Author

otacke commented May 12, 2022

@ilukanets Feel free to change the code the way you want to. I'm not attached to anything. Ultimately, it's not my decision, but the H5P core teams'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants