Chrome for iOS vs. <style>height: 100vh;</style> - javascript

Chrome for iOS hides its address bar when the user scrolls up. This feature does not work well with 100vh (or any vh unit) because as the toolbar shrinks, the viewport height changes and thus the size of the element changes. I have a cover image with 100vh and it causes a very noticeable jitter as the length of the entire page grows or shrinks.
The problem exists for any height set with vh, I think.
I can (and probably will) resort to javascript to set my cover image height, but I'd prefer to use vh.
Any clever ideas?

I'd recommend using 100% instead of 100vh - you can add this...
body{
position: absolute;
width: 100%;
height: 100%;
margin: 0;
}
From there, any element without another wrapper that has its own height will be able to fill the full screen just using width and height at 100%. Example below!
https://codepen.io/will0220/pen/KXqoGZ

Related

I'm manipulating the height of an image using JavaScript, however, at first the image loads with original size and then the JavaScript is applied

The code below takes the height of the navigation (50px, this is important for later) and the height of the viewport then sets the max-height of the image to be viewport height minus navigation height.
I do this so that the image will always be fully visible, no matter how tall it might be. Unfortunately, this has a small drawback.
Whenever I refresh the page, for a split second I could see the image before the JavaScript height has been applied. After comparing the difference in height using Photoshop, I realized the difference is exactly 50px which is the height of the navigation. This makes it clear that the image uses the CSS rules for a split second before the JavaScript kicks in.
Now my question is this - can I make it so that the image doesn't get displayed until the JavaScript manipulation has been applied to the image?
CSS
.specific-image {
display: block;
max-height: 100vh;
max-width: 100%;
margin: 0 auto;
}
JavaScript
function fitImage() {
var navHeight = $("nav.navigation").outerHeight();
var viewport = $(window).height();
$(".specific-image").first().css({"max-height":viewport-navHeight});
}

How to scale the viewport to a minimum width

Problem: I have a page that looks terrible <480px and doesn't display enough relevant information to the user.
Attempted Solutions:
(ex. 320px screen) set the initial scale to 1.5, but then I need to set the scale accordingly for all the screen sizes between 320-480px.
(ex. 320px screen) set the width of your viewport to 480px, however this makes you need to scroll around the screen instead of zooming out like setting the scale would do.
Question: What it seems I need is a combination of the two solutions. One that will scale my viewport, but only until it shows a min-width such as 480px worth of content on the screen. Is this possible without javascript or is solution #1 what I would need to do?
Other considerations: Solution needs to work on all browsers/mobile (IE11+)
I'm not 100% sure what you are trying to do but if I understand correctly, you can set this in css. Setting the width to 100% will keep it flexible to your viewport window & setting a minimum width will not allow it it get any smaller than that.
html,body {
width: 100%;
min-width: 480px;
height: auto;
}
Have you attempted to use media queries ?
For example:
#media screen and (min-width: 480px) {
body {
background-color: lightgreen;
}
}

Downside of html & body height 100%?

I create overlays on facebook games. These games are displayed within iframes.
I can render either 500px * 500px or 700px * 700px;
I have to detect the size of the iframe that embeds the game to know what overlay I should render.
The only suitable technique I found was to create a div with width 100% and height 100%, and then to retrieve his size with javascript.
html, body {
height: 100%;
margin: 0px;
}
.container {
height: 100%;
background: #f0e68c;
}
The condition to make it work is to set html and body height to 100%. Else the container's height retrieved is 0.
My question is: do you think that body height = 100% and html height = 100% can break the page that contains the game ?
I want to believe it does not have any consequence on the page :)
But in the same time, I know that the default value for body and html is auto, not 100%.
I might be missing some key piece of information here.
What do you think ?
Thank for your advices !
No, style rules within an iframe cannot impact the parent page.
Setting height to 100% means that it will always take the size of the viewport. As you are including an iframe that does not impact any other DOM element outside, it will not impact on your website

children iframe as background video and keep ratio

I want to set an iframe.children video of any website as a div.parent background. the children iframe will always be bigger than parent div and parent div overflow will be hidden. Iframe will also keep aspect ratio. I found some jquery plugins but I want to understand how it works. Please help me.
What you're talking about is basically intrinsic ratio†. A ratio must maintain width and height at a constant relative value so when width increases or decreases, the height of a video does likewise of course. We can do this by creating a container (usually a <div>) that has the desired dimensions (usually 16:9 for widescreen or 4:3) and place the iframe and/or video within that container.
The technique commonly employed for a responsive video embedded within an iframe is as follows:
box (a.k.a container, or wrapper)
This div will be triggered by any re-sizing. For any element in the DOM a re-size involves calculation of height and width at the least.
Further down this post I made a simple demo.
Notice the width: 100%and the padding-bottom: 56.25%.
If width increases from 100px to 200px , then height increases from 56.25px to 112.5px.
The ratio of 16:9 is constantly maintained by setting the padding-bottom: 56.25%. If you have an older video with the aspect ratio‡ of 4:3, you'd use padding-bottom: 75% If you have a non-standard aspect ratio like 8:21, you can find the padding-bottom percentage by dividing the denominator by the numerator like so: 8/21 = .38 = 38% (The quotient was rounded down).
So the funky padding-bottom percentage acts like an inflatable cushion that inflates or deflates according to when width changes, but only enough to re-size the height within the parameters of the ratio.
The extra padding-topis to counter the huge padding-bottom otherwise the video will be pushed too far and cause overlapping of elements. The height:0 is probably not necessary as this weird value was to deal with I.E.6. I just left it in there just for that edge case (you know just in case you time traveled back to 2001 or you live in a cave in the middle of the Gobe Desert.)
iframe
The rule sets for the iframe are a lot easier to explain. Simply put, the iframe (and the video) height and width are stretched to fit perfectly within .box. So basically it's .box that does all the work and the iframe goes along and conforms to the dimensions of .box.
.box {
position: relative;
padding-bottom: 56.25%;
/* [56.25%= 16:9 ] [ 75% = 4:3 ] [ 41.66% = 24:10 ] */
padding-top: 25px;
height: 0;
}
.box iframe {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
<div class="box">
<iframe id="ifrm" src="https://arcx.s3.amazonaws.com/av/test.html"></iframe>
</div>
By now you should be thoroughly confused by my ramblings, so I strongly advise you to read these articles:
Creating Intrinsic Ratios for Video
Fluid Width Video
What is Aspect Ratio?‡
A Box with an Intrinsic Ratio†

Need responsive iframe (div) / fixed aspect ratio / centered horizontally and vertically / that SCALES itself so it's not getting browser-cropped

Oh man this is frustrating. I always thought I know my way around HTML and CSS but this is driving me crazy!
I have a blank black HTML page only containing a 16:9 iframe with the id "content".
In this iframe videos and photos with an 16:9 aspect ratio will be shown to the user (this will be an offline application running in Firefox, something like a primitive media player).
Everything inside the iframe works (quite an elaborate multimedia experience) everything is fine EXCEPT the placement/dimensions of that "player" iframe on the blank index page!
It needs to be centered VERTICALLY with a width of 100% thus touching both sides of the browser window,
it needs to be responsive when the browser windows is resized but needs to keep its aspect ratio of course,
and most important; it must always be completely visible! Meaning I must NOT be cropped by the browser window!
No big deal I reckon with tall 4:3 or 5:4 displays, when centered vertically there will be bars at the top and the bottom of the iframe (the black HTML body) and it won't be cropped anywhere.
But kind of a big deal with 16:10 an 16:9 displays since the browser toolbars and the Windows task bar and what have you screw everything up, the aspect ratio isn't really 16:9 or 16:10 anymore when the browser is maximized. So the 16:9 iframe would not be completely visible, it would get cropped a the bottom.
(or maybe the user hasn't even maximized the browser and uses the application in an awkward proportioned window with an even more extreme aspect ratio).
So the iframe needs to STOP growing responsively before its bottom side gets cropped by the browser window. Never be taller than 100vh.
I tried A LOT and in the end I had convoluted div-arrays with a shtload of CSS that accomplished almost everything except the bottom clipping.
I am aware of things like "vh" and "vw" and "max-height" and what have you and I tried A LOT. Never got that iframe from being cropped at the bottom when the browser windows gets too long. I tried things similar to THIS:
Vertically center responsive iframe
but with this the elements height cannot be limited to "100vh" since it uses this padding-workaround for keeping its aspect ratio. :-(
I mean this must be possible, right? A centered (h&v) 16:9 div/iframe that uses as much screen estate as possible but refrains from being cropped anywhere.
HELP PLEASE! Thank you!!
Taken from Bootstrap 3.0, just apply the CSS class and whether it should be 16 by 9 or 4 by 3:
JSfiddle with the result: http://jsfiddle.net/crisbeto/jvcg8v0y/
/* Embeds responsive
Credit: Nicolas Gallagher and SUIT CSS. */
.embed-responsive {
position: relative;
display: block;
height: 0;
padding: 0;
overflow: hidden;
}
.embed-responsive .embed-responsive-item,
.embed-responsive iframe,
.embed-responsive embed,
.embed-responsive object {
position: absolute;
top: 0;
left: 0;
bottom: 0;
height: 100%;
width: 100%;
border: 0;
}
.embed-responsive.embed-responsive-16by9 {
padding-bottom: 56.25%;
}
.embed-responsive.embed-responsive-4by3 {
padding-bottom: 75%;
}
create a <div> and give that the ID "pusher" like this:
<div id="pusher"></div>
and then add these css properties:
#pusher{
height: 50%;
}
now set the css properties for your iframe, Give this a top-margin of minus half the height of the iframe, so if the iframe was 300 pixels heigh, your css for the iframe would be:
iframe{
margin-top: -150px;
}
you could probaly use:
iframe{
height: 100%;
width: 100%;
margin-top: -50%;
}
when you apply this method, what you basicly do is push all content to the vertical center of the screen, that way the "origin point" is at the center of the screen (vertical) now to center it like you needed you are applying the negative margin to center the "center point"

Categories