Creating a Flexible Tumult Hype Document within a DIV with no set 'height'

@h_classen @MaxZieb
Thank you so much for this!!
Nevertheless I have a problem. I'm using WordPress with the Plugin "Tumult Hype Animation" for uploading OAM files. If I load up 2 files with this script on the same site, the second one does not work (div is blank).

Is this a known issue? Any ideas how to fix that?
Thank you! :slight_smile:

1 Like

In this thread are multiple approaches so I’d would need to see what you implemented.

Thank you!
This is a testsite: [LINK deleted]
I hope this is what you wanted to see, otherwise let me know what else you want to see.

edit: on this site the animation inside the green div is the only one you should see.

@h_classen sent me a modified script that seems to work pretty nice. I think the author himself should make it public as soon as he thinks it's time for it.

:hugs: Thanks Hans

I replaced the download above. The original code is anyway from Hans so all is fine.

1 Like

Here is another post:

scale-height-only
scale-width-only

The sample document is called "autoheight".
After test, I found it will auto set both width and height in Hype preview or on wordpress site.

So, maybe it should called auto-width-height, auto-proportional, auto-flexible layout or ONE layout :grinning:?

I reduced the code to the following but haven't put it into the download above.
Just if somebody wants it shorter. @h_classen what do you think, okay?

<script>
function layoutRequest(hypeDocument, element, event) {
	var currentLayout = hypeDocument.layoutsForSceneNamed(hypeDocument.currentSceneName())
		.filter(function(layout){ return hypeDocument.currentLayoutName()==layout.name;})[0];
	var hypeElm = document.getElementById(hypeDocument.documentId());
	var newHeight = hypeElm.offsetWidth * currentLayout['height'] / currentLayout['width'];
	hypeElm.style.height = newHeight + 'px';
	hypeDocument.relayoutIfNecessary();
}

if ("HYPE_eventListeners" in window === false) {  window.HYPE_eventListeners = Array(); }
window.HYPE_eventListeners.push({ "type": "HypeLayoutRequest", "callback": layoutRequest });
</script>

And minified:

<script>
function layoutRequest(a,b,c){b=a.layoutsForSceneNamed(a.currentSceneName()).filter(function(d){return a.currentLayoutName()==d.name})[0];c=document.getElementById(a.documentId());c.style.height=c.offsetWidth*b.height/b.width+"px";a.relayoutIfNecessary()}!1==="HYPE_eventListeners"in window&&(window.HYPE_eventListeners=[]);window.HYPE_eventListeners.push({type:"HypeLayoutRequest",callback:layoutRequest});
</script>
5 Likes

i – of course – love it all :slight_smile: :ok_hand:

3 Likes

:grinning:

1 Like

Update: I removed the return false; as this isn't necessary and on the contrary breaks the event callback loop the runtime uses as it proclaims a result of "no change". As this technique only "observes" the return actually disables all other HypeLayoutRequest listener that actually want to change a layout by returning a name. Not return anything fixes the "problem" and allows for an active callback to coexist with this nice helper.

Hello,

First off thank you for such a wonderful script.

Secondly, for some reason on my files, this gap removal removes the gap from my mobile versions of my pages but yet adds a gap to my desktop pages (in Chrome, Safari, Opera, Firefox). Can someone please help?

I have checked my Tumult files and ensured I don't have any objects running off the edge or extended scene layouts and ensured that objects are hidden. When I remove the code you've provided above, my desktop pages work fine, but then my mobile sites have a gap. I've tried looking at the code to fix it but I'm not advanced enough to figure this out.

Here is my site: www.elevatebtt.com

The Branding page is very obvious. Feel free to scale between desktop and mobile window sizes to see what I mean.

please take the unminified code from @MaxZieb's last post above and add a

console.log(newHeight)
right before
hypeDocument.relayoutIfNecessary();

if the logged height is the expected height, but the output in the browser is not ... it might then be a timing-issue ... means Hype overwrites the height set by the script ...

feel free to attach the hypefile for further investigations ...

Thanks for the new info. Unfortunately it doesn't work.

Attached is my Hype document for further investigation.

the download is not open ...

Link should be open now.

someQuirkyFix.hype.zip (2.9 MB)

//////////////
the document is quite heavy and i guess that this is the reason for the false behavior. if the above fix works: i feel like @jonathan should have a look at it ... ¿!

1 Like

Thank you very much for having a look at this. Unfortunately it still seems that it isn't working. Odd...

hm ... it does in my short tests.

perhaps you're expecting something wrong to happen¿

here a example of what the script should do:

  • the desktopscene has got an layoutdimenesion of 1240x900px

  • in the browser the the hypedocument changes to let's say 1000px regarding a browserresize

  • now the script changes the hypedocelements height to 725.806px ... that's all ...

if you open the developertools in safari or chrome and switch to elements you should see the height changing while resizing.

it does in my tests ...

perhaps somebody else could have a look @MaxZieb :wink:

I just realized that it may be a desktop resolution issue. The attached screenshot shows my problem. It works fine as long as the browser window width doesn't exceed 1830px. My desktop is 2560x1440 and when it is full width I get a scroll bar which allows me to scroll down into a black abyss. The wider the web browser window gets, the deeper the black gap gets as well.


then the problem is related to your setup and the script is doing its job :ghost:

Desktoplayoutsize: 1240*900

Layoutwidth in browser for example: 4000px leads to (4000/1240*900) a proportional height of 2903px ... that's it :slight_smile:

image

the script only sets a proportional height regarding a layoutratio ...

Where as you might want to set the height of the document to the height of your content on the scene
OR
simply wrap your hypedoc in another html-element that has a max-height <- in this case to max-heights applied by mediaquery to consider the two layouts

so you may rethink your setup ...

2 Likes