I am trying to work out how to use Hype’s flexible layouts feature to create content that scales proportionally within Wordpress pages. I have managed to get the content to scale proportionally (without distortion) by setting the Hype Scene to be 100% Width, then using the “shrink to fit” behaviour on the contents of the scene. The problem is that while the content scales down nicely, the hype Scene container DIV retains the same height.
As per example below, there is a large gap between the hype content and the Wordpress paragraph (“the quick brown fox”) that appears as you scale the browser window down. http://dypp.lihdev.com/?page_id=19
Setting the scene Height to 100% (in addition to the width) causes the hype file to cover the entire page (over the top of Wordpress menus etc).
Is there a way to make the height of the scene scale down to the the same height as the flexible group contained within the scene contents?
Hype file attached in case this may help. Thanks in advance!
I have been using the above solution now for many project, thank you! However, I currently can not use this solution because my container div is floated.
I have arrived at a workable solution (below) however this relies on my hard-coding the original width and height of the scene as specified in the hype GUI.
var hypeContainer = document.getElementById(hypeDocument.documentId());
hypeContainer.style.border = ‘2px solid red’;
window.onload = window.onresize = function(){
var original_height = 620;
var original_width = 674;
var current_width = document.getElementById(hypeDocument.documentId()).offsetWidth;
var current_height = document.getElementById(hypeDocument.documentId()).offsetHeight;
var new_height = current_width * original_height / original_width;
hypeContainer.style.height = new_height + 'px';
I am wondering if there is any way to fetch the original height&width (specified in the GUI) via javascript?
I have tried this:
var currScene = document.querySelector(’#’+ hypeDocument.documentId()+’ > .HYPE_scene[style*=“block”]’);
var actualWidth = hypeDocument.getElementProperty(currScene, ‘width’);
…however this gives me the calculated width of the scene rather than the original width.
Hello, i have the same problem and the script works perfectly with one hype document on a Wordpress page. But i have 5 different documents on one Wordpress page and only one of the documents shows right. I have no experience with scripts. What need to change in the script to work?
I ran into a similar issue. If you have multiple hype objects on a single wordpress page, this code should help you out. It uses the solutions from Hans (thank you Hans!), but swaps listeners instead of window.onload.
The script needs to be run on scene load, and change the “max-width” value to set the maximum width the file can scale up to. Hope this helps!
Raph
document.getElementById(hypeDocument.documentId()).style["max-width"] = "600px";
var hypeContainer = document.getElementById(hypeDocument.documentId());
var layoutsOfScene =
hypeDocument.layoutsForSceneNamed(hypeDocument.currentSceneName());
var resizeScene = function() {
var currLayoutObj = layoutsOfScene.find(arrayElement => arrayElement.name ==
hypeDocument.currentLayoutName());
var UIWidth = currLayoutObj.width;
var UIHeight = currLayoutObj.height;
var current_width = document.getElementById(hypeDocument.documentId()).offsetWidth;
var new_height = current_width * UIHeight / UIWidth;
hypeContainer.style.height = new_height + 'px';
};
if (window.addEventListener) {
window.addEventListener('load', resizeScene, false);
window.addEventListener('resize', resizeScene, false);
} else if (window.attachEvent) {
window.attachEvent('onload', resizeScene);
window.attachEvent('onresize', resizeScene);
}
In some instances you may also need to call resizeScene() on scene load, add this right at the bottom on a new line: