My application needs to print out an arbitrarily large canvas that can span multiple page width and height widths.
There was a similar question some time back where it was claimed the browser won't print to multiple page widths.
Since this was a while back I am wondering if it is still true. Also, what strategies are available to print out a large canvas without splitting it up?
var canvas = document.getElementById("canvas1");
function draw_a() {
var context = canvas.getContext("2d");
// // LEVER
//plane
context.fillStyle = '#aaa';
context.fillRect(25, 90, 2500, 400);
}
$(document).ready(function() {
draw_a();
});
canvas {
border: 1px dotted;
}
.printOnly {
display: none;
}
#media print {
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
background-color: yellow;
/*
height: 100%;
width: 100%;
position: fixed;*/
top: 0;
left: 0;
margin: 0;
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
}
}
#media print and (-ms-high-contrast: active),
(-ms-high-contrast: none) {
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
background-color: yellow;
/*
height: 100%;
width: 100%;
position: fixed;*/
top: 0;
left: 0;
margin: 0;
padding: 15px;
font-size: 14px;
line-height: 18px;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="window.print();" class="no-print">Print Canvas</button>
<div class="myDivToPrint">
<div class="Aligner-item">
<canvas height="2500px" width="4000px" id="canvas1"></canvas>
<div class="printOnly Aligner-item--bottom"> Print Only</div>
</div>
</div>
It does seem that browsers will split up a large canvas into multiple pages. I tested on MacOS Sierra using latest chrome and safari browsers.
A possible approach for printing a canvas is to first transform it to a data URI containing a representation of the image using canvas.toDataURL(). You can then manipulate the image dimensions prior to printing.
"<img src='" + canvas.toDataURL() + "' height='500px' width='500px' />'"
In the following example, the large 4500px by 4500px canvas is translated into an img and placed inside an iframe, used for printing. You can probably append the image to the original document and than print that specific element, but the iframe may be more flexible to handle print output. You can manipulate the img dimensions according to your requirements and print a scaled representation of the canvas. Note that I hardcoded the width and height of the image but this can be calculated and changed as needed for printing.
Due to iframe cross-origin restrictions, the code snippet below will not work here, but it does work on this jsfiddle.
The scaled 500px by 500px image representing the canvas fits on one page when printed.
var canvas = document.getElementById("canvas1");
function draw_a() {
var context = canvas.getContext("2d");
// // LEVER
//plane
context.fillStyle = '#aaa';
context.fillRect(25, 90, 4500, 4500);
}
print = function() {
window.frames["myFrame"].focus();
window.frames["myFrame"].print();
}
function setupPrintFrame() {
$('<iframe id="myFrame" name="myFrame">').appendTo("body").ready(function(){
setTimeout(function(){
$('#myFrame').contents().find('body').append("<img src='" + canvas.toDataURL() + "' height='500px' width='500px' />'");
},50);
});
}
$(document).ready(function() {
draw_a();
setupPrintFrame();
});
canvas {
border: 1px dotted;
}
.printOnly, #myFrame {
display: none;
}
#media print {
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
background-color: yellow;
/*
height: 100%;
width: 100%;
position: fixed;*/
top: 0;
left: 0;
margin: 0;
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
}
}
#media print and (-ms-high-contrast: active),
(-ms-high-contrast: none) {
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
background-color: yellow;
/*
height: 100%;
width: 100%;
position: fixed;*/
top: 0;
left: 0;
margin: 0;
padding: 15px;
font-size: 14px;
line-height: 18px;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="print()" class="no-print">Print Canvas</button>
<div class="myDivToPrint">
<div class="Aligner-item">
<canvas height="4500px" width="4500px" id="canvas1"></canvas>
<div class="printOnly Aligner-item--bottom"> Print Only</div>
</div>
</div>
#media print {
#page {
size: 297mm 210mm; /* landscape */
/* you can also specify margins here: */
margin: 25mm;
margin-right: 45mm; /* for compatibility with both A4 and Letter */
}
}
var canvas = document.getElementById("canvas1");
function draw_a() {
var context = canvas.getContext("2d");
// // LEVER
//plane
context.fillStyle = '#aaa';
context.fillRect(25, 90, 2500, 400);
}
$(document).ready(function() {
draw_a();
});
canvas {
border: 1px dotted;
}
.printOnly {
display: none;
}
#media print {
#page {
size: 297mm 210mm; /* landscape */
/* you can also specify margins here: */
margin: 25mm;
margin-right: 45mm; /* for compatibility with both A4 and Letter */
}
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
background-color: yellow;
/*
height: 100%;
width: 100%;
position: fixed;*/
top: 0;
left: 0;
margin: 0;
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
}
}
#media print and (-ms-high-contrast: active),
(-ms-high-contrast: none) {
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
background-color: yellow;
/*
height: 100%;
width: 100%;
position: fixed;*/
top: 0;
left: 0;
margin: 0;
padding: 15px;
font-size: 14px;
line-height: 18px;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="window.print();" class="no-print">Print Canvas</button>
<div class="myDivToPrint">
<div class="Aligner-item">
<canvas height="2500px" width="4000px" id="canvas1"></canvas>
<div class="printOnly Aligner-item--bottom"> Print Only</div>
</div>
</div>
Try this!
var canvas = document.getElementById("canvas1");
function draw_a() {
var context = canvas.getContext("2d");
context.fillStyle = '#aaa';
context.fillRect (25, 90, 2500, 400);
}
$(document).ready(function(){
draw_a();
});
#page Section1 {
size:8.27in 11.69in;
margin:0;
mso-header-margin:0;
mso-footer-margin:0;
mso-paper-source:0;
}
<button onclick="window.print();" class="no-print">Print Canvas</button>
<div class="myDivToPrint">
<div class="Aligner-item">
<canvas height="2500px" width="4000px" id="canvas1" style="border: solid 10px #000;"></canvas>
</div>
</div>
I just tested this fiddle in both browsers firefox and chrome using a localhost environment and it worked within both. Here is the original js fiddle
And here is the html I tested
var canvas = document.getElementById("canvas1");
function draw_a() {
var context = canvas.getContext("2d");
// // LEVER
//plane
context.fillStyle = '#aaa';
context.fillRect(25, 90, 2500, 400);
}
$(document).ready(function() {
draw_a();
});
div.sizePage {
color: #333;
}
canvas {
border: 1px dotted;
}
.printOnly {
display: none;
}
#media print {
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
background-color: yellow;
/*
height: 100%;
width: 100%;
position: fixed;*/
top: 0;
left: 0;
margin: 0;
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
}
}
#media print and (-ms-high-contrast: active),
(-ms-high-contrast: none) {
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
background-color: yellow;
/*
height: 100%;
width: 100%;
position: fixed;*/
top: 0;
left: 0;
margin: 0;
padding: 15px;
font-size: 14px;
line-height: 18px;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="window.print();" class="no-print">Print Canvas</button>
<div class="myDivToPrint">
<div class="Aligner-item">
<canvas height="2500px" width="4000px" id="canvas1"></canvas>
<div class="printOnly Aligner-item--bottom"> Print Only</div>
</div>
</div>
So I thinks it's safe to say that it is supported in both browsers now.
I am using the most recent update on both browsers.
It is impossible to handle this problem using plain CSS styles.
I recommend to clone element to print multiple times (in this case), put copies after each other and make them "print only" using CSS. Additionally, canvas can't be just cloned - it needs to be redrawn for each copy.
Number of copies depends on the element and page widths.
Default page width is 210mm, it can be converted to px (Pixel to Centimeter?) and compared to the element's width.
When we have page width in pixels, we can set negative left margin for each copy respectively. Having that, entire canvas will be "divided" into columns and printed from top to bottom.
In order to have each copy printed starting from the new page, simple use this CSS rule:
page-break-before: always;
There is a lot of hardcoded things, however I think that you could use it to build a generic solution for your problem.
var divide = function(selector, pageWidth) {
var elementToDivide = document.querySelector(selector);
var widthPx = elementToDivide.offsetWidth;
var pageWidthPx = pageWidth * 3.7795;
for (var i = 1; i <= parseInt(widthPx/pageWidthPx); i++) {
var clone = elementToDivide.cloneNode(true);
elementToDivide.parentNode.appendChild(clone);
draw_a(document.getElementsByTagName("canvas"))
clone.style.marginLeft = "-" + (pageWidthPx * i) + "px";
clone.className += " printOnly";
}
}
var standardPrint = window.print;
window.print = function() {
if (!window.pagesDivided) {
divide(".myDivToPrint", 210);
window.pagesDivided = true;
}
standardPrint();
};
function draw(canvas) {
var context = canvas.getContext("2d");
var grd = context.createLinearGradient(0, 0, 4000, 2500);
grd.addColorStop(0, "yellow");
grd.addColorStop(1, "red");
context.fillStyle = grd;
context.fillRect(25, 25, 4000, 2500);
}
function draw_a(elem) {
if (elem.length != null && elem.length > 1) {
for (var i = 0; i < elem.length; i++) {
draw(elem[i]);
}
} else {
draw(elem);
}
}
$(document).ready(function() {
draw_a(document.getElementById("canvas1"));
});
canvas {
border: 5px dashed;
}
.printOnly {
display: none;
}
.myDivToPrint {
float: left;
}
#media print {
#page {
size: 297mm 210mm;
margin: 0mm;
margin-right: 0mm;
}
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
page-break-before: always;
background-color: yellow;
margin: 0;
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
page-break-before: always;
}
}
#media print and (-ms-high-contrast: active),
(-ms-high-contrast: none) {
html,
body {
height: 100%;
background-color: yellow;
}
.myDivToPrint {
background-color: yellow;
top: 0;
left: 0;
margin: 0;
padding: 15px;
font-size: 14px;
line-height: 18px;
align-items: center;
justify-content: center;
}
.no-print,
.no-print * {
display: none !important;
}
.printOnly {
display: block;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="window.print();" class="no-print">Print Canvas</button>
<div class="myDivToPrint">
<div class="Aligner-item">
<canvas height="2500px" width="4000px" id="canvas1"></canvas>
<div class="printOnly Aligner-item--bottom"> Print Only</div>
</div>
</div>
Related
Im trying to make a sidebar with variable width, but for some reason the #media rules are not triggering when changing manually the size of the bar:
In this simplifyed example, the background-color should change when the sidebar width is less than 350px, according to the following rule, but is not working, can't understand why
#media only screen and (max-width: 350px) {
.sidebar {
background-color: aqua;
}
}
Here it is a working code example:
let sidebar = document.querySelector(".sidebar");
let dragholder = document.querySelector(".dragholder");
function onMouseMove(e) {
sidebar.style.cssText = `width: ${ e.pageX }px`;
}
function onMouseDown(e) {
document.addEventListener('mousemove', onMouseMove);
}
function onMouseUp(e) {
document.removeEventListener('mousemove', onMouseMove);
}
dragholder.addEventListener('mousedown', onMouseDown);
dragholder.addEventListener('mouseup', onMouseUp);
document.addEventListener('mouseup', onMouseUp);
.sidebar {
height: 100vh;
position: fixed;
top: 0;
left: 0;
background-color: #2D2D30;
width: 450px;
color: #FFF;
padding: 5px;
box-sizing: border-box;
}
.dragholder {
position: absolute;
height: 100vh;
width: 5px;
background: yellow;
right: -5px;
top: 50%;
transform: translate(-50%, -50%);
border-radius: 80px;
}
.dragholder:hover {
cursor: col-resize;
}
#media only screen and (max-width: 350px) {
.sidebar {
background-color: aqua;
}
}
<div class="sidebar"> TEST 123
<div class="dragholder"></div>
</div>
I need to create a fairly static page divided into regions with an image carousel on the right (hcentered and vcentered)
This needs to be very browser compatible, so flexbox is not really an option
Here is a mockup image of what I'm after:
Mockup
The Code I have thus far is as follows, but I can for the life of me not get the right hand image to be centered and middle aligned:
$(function() {
// var exits = ['fadeOut', 'fadeOutDown', 'fadeOutUpBig', 'bounceOut', 'bounceOutDown', 'hinge',
// 'bounceOutUp', 'bounceOutLeft', 'rotateOut', 'rotateOutUpLeft', 'lightSpeedOut', 'rollOut'];
// var entrances = ['fadeIn', 'fadeInDown', 'fadeInRight', 'bounceIn', 'bounceInRight', 'rotateIn',
// 'rotateInDownLeft', 'lightSpeedIn', 'rollIn', 'bounceInDown' ];
var exits = ['fadeOut'];
var entrances = ['fadeInRight'];
var photos = $('#photos'),
ignoreClicks = false;
$('.arrow').click(function(e, simulated) {
if (ignoreClicks) {
// If clicks on the arrows should be ignored,
// stop the event from triggering the rest
// of the handlers
e.stopImmediatePropagation();
return false;
}
// Otherwise allo this click to proceed,
// but raise the ignoreClicks flag
ignoreClicks = true;
if (!simulated) {
// Once the user clicks on the arrows,
// stop the automatic slideshow
clearInterval(slideshow);
}
});
// Listen for clicks on the next arrow
$('.arrow.next').click(function(e) {
e.preventDefault();
// The topmost element
var elem = $('#photos #innerdiv:last');
// Apply a random exit animation
elem.addClass('animated')
.addClass(exits[Math.floor(exits.length * Math.random())]);
setTimeout(function() {
// Reset the classes
elem.attr('class', '').prependTo(photos);
// The animation is complate!
// Allow clicks again:
ignoreClicks = false;
}, 10);
});
// Start an automatic slideshow
var slideshow = setInterval(function() {
// Simulate a click every 1.5 seconds
$('.arrow.next').trigger('click', [true]);
}, 1000);
});
/* https://tutorialzine.com/2013/02/animated-css3-photo-stack */
body {
/* overflow:hidden;*/
}
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
#photos {
/* margin:0 auto; */
/*position:relative; */
}
#photos .outerdiv {
position: relative;
}
#photos .middlediv {
/* position:absolute; */
/* display:inline-block; */
/* width:450px; */
/* height:450px; */
/* overflow:hidden; */
background-color: #fff;
z-index: 10;
border: 1px solid #aaa;
/* -webkit-animation-duration: 1s; */
-moz-animation-duration: 1s;
/* animation-duration: 1s; */
}
#photos .innerdiv {
/* position:absolute; */
/* top:0px; */
/* left:0px; */
/* right:0px; */
/* bottom:0px; */
width: 450px;
height: 450px;
background-size: cover;
background-position: center;
/*overflow:hidden;*/
/* width:400px; */
/* height:400px; */
position: absolute;
}
.lefttop {
grid-area: lefttop;
width: 50vw;
height: 33.3vh
}
.leftcenter {
grid-area: leftcenter;
width: 50vw;
height: 33.3vh
}
.leftbottom {
grid-area: leftbottom;
width: 50vw;
height: 33.3vh
}
.rightfull {
grid-area: rightfull;
width: 50vw;
}
.grid-container {
display: grid;
grid-template-areas: 'lefttop rightfull' 'leftcenter rightfull' 'leftbottom rightfull';
grid-gap: 1px;
background-color: #2196F3;
padding: 1px;
}
.grid-container>div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 0px;
font-size: 30px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="grid-container">
<div class="lefttop">left top</div>
<div class="leftcenter">left center</div>
<div class="leftbottom">left bottom </div>
<div class="rightfull">
<div id="photos" class="outerdiv">
<div class="middlediv">
<div class="innerdiv" style="background-image:url(http://127.0.0.1:81/wordpress/wp-content/uploads/2018/08/20180823_132842-01-400x347.jpeg)"></div>
</div>
<div class="middlediv">
<div class="innerdiv" style="background-image:url(http://127.0.0.1:81/wordpress/wp-content/uploads/2018/07/20180806_162813-01-1-400x389.jpeg)"></div>
</div>
<div class="middlediv">
<div class="innerdiv" style="background-image:url(http://127.0.0.1:81/wordpress/wp-content/uploads/2018/08/20180820_153720-01-400x356.jpeg)"></div>
</div>
</div>
</div>
</div>
Ideally, I would want to use grid or table but it seems like table does not allow for vertical merging of cells.
IE10 and above needs to be supported.
The image in the carousel should be a percentage of the width or height of the right hand column to make it relatively responsive to different screen sizes.
I have used the photo carousel at https://tutorialzine.com/2013/02/animated-css3-photo-stack and modified the code and javascript slightly as I thought using divs would be easier than UL's and LI's, but the results are just about the same.
Any guidance on how to achieve this without too many dirty fixes would be very much appreciated!
In other words:
a simple page, divided into two equal columns.
The left column should have a logo and some links spaced vertically away from the middle horizontal line of the screen.
The right column should be half the screen width, and full screen height with the image carousel centered and middle of the column with responsive width and height.
here is a fiddle with your requirement, I was based on the mock image in your question, I hope this help you.
Here is the HTML:
<div class="grid-container">
<div class="lefttop">
<h1>
LOGO
</h1>
</div>
<div class="leftbottom">
<ul>
<li>
home
</li>
<li>
about
</li>
<li>
contact
</li>
</ul>
</div>
<div class="rightfull">
<div id="photos" class="outerdiv">
<div class="middlediv">
<img class="innerdiv" src="https://picsum.photos/200/300/?random">
</div>
<div class="middlediv">
<img class="innerdiv" src="https://picsum.photos/200/300/?random">
</div>
<div class="middlediv">
<img class="innerdiv" src="https://picsum.photos/200/300/?random">
</div>
</div>
</div>
</div>
And tht SCSS
/* https://tutorialzine.com/2013/02/animated-css3-photo-stack */
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html, body {
height: 100%;
}
.grid-container {
overflow: hidden;
display: grid;
height: 100% !important;
grid-template-columns: repeat(2, 50%);
grid-template-rows: repeat(2, 50%);
background-color: #2196F3;
& > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: center;
padding: 0px;
// font-size: 30px;
}
.lefttop, .leftbottom {
grid-column: 1;
}
.lefttop {
&::before, & > h1 {
display: inline-block;
vertical-align: bottom;
}
&::before {
content: '';
height: 100%;
}
grid-row: 1;
position: relative;
h1 {
font-size: 3rem;
font-weight: 100;
}
}
.leftbottom {
grid-row: 2;
ul {
margin: 1rem auto;
li {
list-style: none;
display: inline;
&:not(:first-child):not(:last-child)::before {
content: '-';
}
&:not(:first-child):not(:last-child)::after {
content: '-';
}
a {
text-decoration: none;
color: inherit;
}
}
}
}
.rightfull {
grid-column: 2 / 3;
grid-row: 1 / 3;
position: relative;
img {
top: 0;
left: 0;
padding: 1rem;
position: absolute;
width: 100%;
height: 100%;
object-fit: cover;
}
}
}
https://jsfiddle.net/cisco336/wpfzL03k/1/
Here is MS Edge screenshot
MS IE11 screenshot
There should be a simple solution, but I can't work one out. I need div with class of geltona to slide onto div with class of zydra. I must use only css, but I can't. It might be obvious, but I can't find a solution as I am only using floats and % in width and height, so I can't really set a location where it should go by keyframes.
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
p {
margin: 10px;
}
.header {
height: 5%;
width: 100%;
}
.geltona {
height: 15%;
width: 50%;
background-color: yellow;
float: left;
}
.zydra {
height: 15%;
width: 50%;
background-color: lightblue;
float: right;
}
.balta {
height: 30%;
width: 70%;
background-color: white;
float: left;
}
.juoda {
height: 75%;
width: 30%;
background-color: black;
float: right;
}
.oranzine {
height: 20%;
width: 35%;
background-color: orange;
display: inline;
float: left;
}
.melyna {
position: relative;
height: 45%;
width: 35%;
background-color: blue;
float: right;
}
.zalia {
height: 25%;
width: 35%;
background-color: green;
float: left;
}
.ruda {
height: 5%;
width: 100%;
background-color: brown;
float: left;
}
/* ANIMACIJOS */
/* 3. Blokas animuotai nukeliauja ant gretimo bloko, pilnai uždengęs gretimą bloką – išnyksta */
/* 20. Pasisuka nuo 45 laipsnių iki 0 laipsnių ir padidėja 30%; */
.zalia:hover {
animation: sukasi 3s;
}
#keyframes sukasi {
0%{transform: rotate(45deg)}
100%{transform: rotate(0deg) scale(1.3)};
}
/* 21. Nuotrauka atslenka iš viršaus ir mažėja (trukmė 5 sec); */
.header img {
position: absolute;
top: -145px;
max-width: 145px;
max-height: 145px;
background: transparent;
transition: 5s;
}
.header:hover img {
transition: 5s;
top: 0;
max-width: 45px;
max-height: 45px;
}
/* MEDIA QUERIES */
#media only screen and (max-width: 768px) and (max-height: 1024px){
.geltona {
height: 25%;
width: 100%;
}
.zydra {
display: none;
}
.balta {
height: 20%;
width: 70%;
}
.juoda {
height: 65%;
width: 30%;
}
.oranzine {
display: none;
}
.melyna {
height: 45%;
width: 40%;
}
.zalia {
height: 45%;
width: 30%;
}
}
<!DOCTYPE html>
<html>
<head>
<title>IPP Kursinis</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" content="initial-scale=1">
<link rel="stylesheet" type="text/css" href="src/css/main.css">
</head>
<body>
<div class="header">
<img src="img/foto.jpg">
</div>
<div class="geltona"></div>
<div class="zydra"
id="keiciamaSpalva"
onmouseover="changeBackground(this.id, 'red', 'yellow');"
onmouseout="changeBackground(this.id, 'lightblue', 'black');">
<p>Lorem ipsum</p>
</div>
<div class="balta"
id="balta"
onmouseover="showClass();"
onmouseout="removeClass();">
</div>
<div class="juoda"></div>
<div class="oranzine"></div>
<div class="melyna">
<p id="demo"></p>
</div>
<div class="zalia"></div>
<div class="ruda"></div>
<!-- JAVASCRIPT prasideda nuo čia -->
<script type="text/javascript">
/* Keičiama teksto ir fono spalva pagal nurodymus. */
function changeBackground(id, color, textColor) {
document.getElementById(id).style.background = color;
document.getElementById(id).style.color = textColor;
};
/* Parodome bloko klasę ir ją ištriname, kad nesipildytų visas blokas*/
function showClass() {
var element = document.getElementById('balta');
element.innerHTML = element.innerHTML + "<p> Šio bloko klasė: "+element.className+"</p>";
};
function removeClass() {
document.getElementById('balta').innerHTML = "";
};
/* Rodoma lango, ekrano ir slankiklių informacija, tik tuomet, kai keičiame ekrano dydį. */
window.onresize = displayWindowSize;
function displayWindowSize(){
document.getElementById("demo").innerHTML =
"Ekrano plotis: " + screen.width + "<br>" +
"Ekrano aukštis: " + screen.height + "<br>" +
"Lango plotis: " + window.innerWidth + "<br>" +
"Lango aukštis: " + window.innerHeight + "<br>" +
"Slankiklio horizontali padėtis: " + window.scrollX + "<br>" +
"Slankiklio vertikali padėtis: " + window.scrollY;
};
</script>
</body>
</html>
With the least amount of changes for this code, I came up with this.
Wrap your two neighbouring containers (geltona and zydra) in another container (gelzy here) and give it the position:relative and the two child containers the position:absolute with left:0 and right:0 instead of the floats.
Make use of the transition on hover to move the geltona (with higher z-index)to 50% of the left to overlap on the blue container
.gelzy{
position:relative;
height:15%;
width:100%;
}
.geltona {
height: 100%;
width: 50%;
background-color: yellow;
left:0;
position: absolute;
z-index:2;
transition:left 1s ease-in-out;
}
.zydra {
height: 100%;
width: 50%;
background-color: lightblue;
right:0;
position: absolute;
}
.geltona:hover {
left:50%;
}
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
p {
margin: 10px;
}
.header {
height: 5%;
width: 100%;
}
.gelzy{
position:relative;
height:15%;
width:100%;
}
.geltona {
height: 100%;
width: 50%;
background-color: yellow;
left:0;
position: absolute;
z-index:2;
transition:left 1s ease-in-out;
}
.zydra {
height: 100%;
width: 50%;
background-color: lightblue;
right:0;
position: absolute;
}
.geltona:hover {
left:50%;
}
.balta {
height: 30%;
width: 70%;
background-color: white;
float: left;
}
.juoda {
height: 75%;
width: 30%;
background-color: black;
float: right;
}
.oranzine {
height: 20%;
width: 35%;
background-color: orange;
display: inline;
float: left;
}
.melyna {
position: relative;
height: 45%;
width: 35%;
background-color: blue;
float: right;
}
.zalia {
height: 25%;
width: 35%;
background-color: green;
float: left;
}
.ruda {
height: 5%;
width: 100%;
background-color: brown;
float: left;
}
/* ANIMACIJOS */
/* 3. Blokas animuotai nukeliauja ant gretimo bloko, pilnai uždengęs gretimą bloką – išnyksta */
/* 20. Pasisuka nuo 45 laipsnių iki 0 laipsnių ir padidėja 30%; */
.zalia:hover {
animation: sukasi 3s;
}
#keyframes sukasi {
0% {
transform: rotate(45deg)
}
100% {
transform: rotate(0deg) scale(1.3)
}
;
}
/* 21. Nuotrauka atslenka iš viršaus ir mažėja (trukmė 5 sec); */
.header img {
position: absolute;
top: -145px;
max-width: 145px;
max-height: 145px;
background: transparent;
transition: 5s;
}
.header:hover img {
transition: 5s;
top: 0;
max-width: 45px;
max-height: 45px;
}
/* MEDIA QUERIES */
#media only screen and (max-width: 768px) and (max-height: 1024px) {
.geltona {
height: 25%;
width: 100%;
}
.zydra {
display: none;
}
.balta {
height: 20%;
width: 70%;
}
.juoda {
height: 65%;
width: 30%;
}
.oranzine {
display: none;
}
.melyna {
height: 45%;
width: 40%;
}
.zalia {
height: 45%;
width: 30%;
}
}
<!DOCTYPE html>
<html>
<head>
<title>IPP Kursinis</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" content="initial-scale=1">
<link rel="stylesheet" type="text/css" href="src/css/main.css">
</head>
<body>
<div class="header">
<img src="img/foto.jpg">
</div>
<div class="gelzy">
<div class="geltona"></div>
<div class="zydra" id="keiciamaSpalva" onmouseover="changeBackground(this.id, 'red', 'yellow');" onmouseout="changeBackground(this.id, 'lightblue', 'black');">
<p>Lorem ipsum</p>
</div>
</div>
<div class="balta" id="balta" onmouseover="showClass();" onmouseout="removeClass();">
</div>
<div class="juoda"></div>
<div class="oranzine"></div>
<div class="melyna">
<p id="demo"></p>
</div>
<div class="zalia"></div>
<div class="ruda"></div>
<!-- JAVASCRIPT prasideda nuo čia -->
<script type="text/javascript">
/* Keičiama teksto ir fono spalva pagal nurodymus. */
function changeBackground(id, color, textColor) {
document.getElementById(id).style.background = color;
document.getElementById(id).style.color = textColor;
};
/* Parodome bloko klasę ir ją ištriname, kad nesipildytų visas blokas*/
function showClass() {
var element = document.getElementById('balta');
element.innerHTML = element.innerHTML + "<p> Šio bloko klasė: " + element.className + "</p>";
};
function removeClass() {
document.getElementById('balta').innerHTML = "";
};
/* Rodoma lango, ekrano ir slankiklių informacija, tik tuomet, kai keičiame ekrano dydį. */
window.onresize = displayWindowSize;
function displayWindowSize() {
document.getElementById("demo").innerHTML =
"Ekrano plotis: " + screen.width + "<br>" +
"Ekrano aukštis: " + screen.height + "<br>" +
"Lango plotis: " + window.innerWidth + "<br>" +
"Lango aukštis: " + window.innerHeight + "<br>" +
"Slankiklio horizontali padėtis: " + window.scrollX + "<br>" +
"Slankiklio vertikali padėtis: " + window.scrollY;
};
</script>
</body>
</html>
I've created this website on codepen. While trying to make it responsive for all platforms I ran into a problem. It appears a single div covers the whole page (only on IOS) and not all heights are working properly (meaning nothing fits).
I've been at it for days and still have no clue, why all the heights and rules don't apply on IOS.
I've tried removing the video-section which reveals most of the page except the eind section which is just a blank white.
I've tried adding max-height which does reveal some of the other content, but it also seems as if the page can't get any taller on IOS so I'm still limited to a space to work with. Also it doesn't seem a proper solution.
I've tried changing the position but with no avail.
It just seems as if the heights don't properly work on IOS
Can anyone help me figure out why this is happening?
var $animation_elements = $('.animation-element');
var $window = $(window);
function check_if_in_view() {
var window_height = $window.height();
var window_top_position = $window.scrollTop();
var window_bottom_position = (window_top_position + window_height);
$.each($animation_elements, function() {
var $element = $(this);
var element_height = $element.outerHeight();
var element_top_position = $element.offset().top;
var element_bottom_position = (element_top_position + element_height);
//check to see if this current container is within viewport
if ((element_bottom_position >= window_top_position) &&
(element_top_position <= window_bottom_position)) {
$element.addClass('in-view');
} else {
$element.removeClass('in-view');
}
});
}
$window.on('scroll resize', check_if_in_view);
$window.trigger('scroll');
var controller = new ScrollMagic();
var ctrl = new ScrollMagic.Controller({
globalSceneOptions: {
triggerHook: 'onLeave'
}
});
//Enter section-1
new ScrollMagic.Scene({
triggerElement: "#coming-soon",
duration: "100%"
})
.setTween(TweenMax.to("#image-1", 1, { top: "0%" }))
.addTo(ctrl);
new ScrollMagic.Scene({
triggerElement: "#coming-soon",
duration: "100%"
})
.setTween(TweenMax.to(".sign-up-banner", 1, { top: "0%" }))
.addTo(ctrl);
new ScrollMagic.Scene({
triggerElement: "#coming-soon",
duration: "100%"
})
.setTween(TweenMax.to("#text-1", 1, { top: "0%" }))
.addTo(ctrl);
//Leave section-1
new ScrollMagic.Scene({
triggerElement: "#introductie-1",
duration: "100%"
})
.setTween(TweenMax.to("#image-1", 1, { top: "40%", opacity:-1 }))
.addTo(ctrl);
new ScrollMagic.Scene({
triggerElement: "#introductie-1",
duration: "100%"
})
.setTween(TweenMax.to("#text-1", 1, { top: "-50%", opacity:0 }))
.addTo(ctrl);
//leave seaction-2
new ScrollMagic.Scene({
triggerElement: "#introductie-2",
duration: "100%"
})
.setTween(TweenMax.to("#image-2", 1, { top: "-40%", opacity:0 }))
.addTo(ctrl);
new ScrollMagic.Scene({
triggerElement: "#introductie-2",
duration: "100%"
})
.setTween(TweenMax.to("#text-2", 1, { top: "-50%", opacity:0 }))
.addTo(ctrl);
new ScrollMagic.Scene({
triggerElement: "#introductie-2",
duration: "100%"
})
.setTween(TweenMax.to("#release", 1, {opacity:1 }))
.addTo(ctrl);
#import url("https://fonts.googleapis.com/css?family=Raleway:200");
* {
font-family: "Raleway", sans-serif;
font-size: 14px;
font-weight: 100 !important;
}
input {
-webkit-appearance: none;
}
html,
body,
section {
padding: 0px;
margin: 0px;
height: 100%;
width: 100%;
color: #666;
}
p,
h1,
h2,
h3,
h4 {
margin: 0px;
}
ul {
list-style-type: none;
}
ul li {
display: inline-block;
margin: 50px 25px;
}
ul li .fa {
font-size: 5em;
transition: all 1s ease;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
a {
color: #666;
}
.desktop-only {
display: initial;
}
.align-center {
position: absolute !important;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
}
.mobile-only {
display: none;
}
.icon {
background-color: antiquewhite;
border-radius: 50%;
width: 150px;
height: 150px;
margin: 20px auto;
}
.fa-icon {
font-size: 5em !important;
padding: 40px;
}
.nederland-icon {
width: 40%;
padding: 40px;
}
#mc_embed_signup form {
position: absolute !important;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
/* (x, y) => position */
-ms-transform: translate(-50%, -50%);
/* IE 9 */
-webkit-transform: translate(-50%, -50%);
/* Chrome, Safari, Opera */
padding-left: 0px !important;
}
.sign-up-banner {
z-index: 2;
position: relative;
top: -50%;
color: white;
height: 50%;
background-color: #f3c17e;
}
.sign-up-banner input::placeholder {
color: white;
}
.sign-up-banner #mc_embed_signup .mc-field-group input {
border-bottom: 2px solid #ffffff !important;
}
.sign-up-banner #mc_embed_signup {
background: #fff0;
}
.sign-up-banner #mc_embed_signup .mc-field-group input {
background-color: #ffffff00;
color: white;
}
.sign-up-banner #mc_embed_signup #mc-embedded-subscribe-form div.mce_inline_error {
background-color: rgba(255, 255, 255, 0);
}
.video-section {
z-index: 3;
overflow: hidden;
position: relative;
top: 0px;
background-color: black;
max-height: 100%;
max-height: 100vh;
}
.video-section video {
width: 100%;
}
#coming-soon {
display: table;
position: absolute;
height: 100%;
width: 100%;
top: 0px;
color: white !important;
z-index: 3;
max-height: 100%;
max-height: 100vh;
}
.coming-soon h1 {
font-size: 52px;
}
.introductie {
position: relative;
z-index: 1;
}
#introductie-1 {
height: 100%;
}
#introductie-1 #image-1 {
overflow: hidden;
width: 25%;
margin: 90px auto;
max-height: 70%;
}
#introductie-1 .text-container {
width: 500px;
margin: 180px auto;
color: #666;
}
#introductie-1 .text-container h1 {
font-size: 2em;
margin-bottom: 40px;
}
#introductie-1 .text-container p {
font-size: 1.4em;
}
#introductie-2 {
height: 100%;
}
#introductie-2 h1 {
font-size: 2em;
margin-bottom: 40px;
}
#introductie-2 p {
font-size: 1.4em;
}
#introductie-2 .text-container {
width: 60%;
text-align: center;
margin: 0 auto;
}
#introductie-2 #text-2 {
position: relative;
}
#introductie-2 #image-2 {
overflow: hidden;
width: 60%;
margin: 90px auto;
position: relative;
}
#introductie-2 #image-2 img {
width: 100%;
}
.left,
.right {
width: 50%;
}
.left {
float: left;
}
.right {
float: right;
}
#image-1 {
position: absolute;
top: -70%;
left: 10%;
}
#text-1 {
top: 40%;
right: 10%;
position: absolute;
}
.center-container {
display: table-cell;
vertical-align: middle;
}
.center {
margin-left: auto;
margin-right: auto;
width: 80%;
}
.center-text {
text-align: center;
overflow: hidden;
}
#eind {
position: relative;
}
#release {
opacity: 0;
}
#disclaimer {
position: relative;
left: 48%;
bottom: 10px;
}
.fa-facebook:hover {
color: #3b5998;
}
.fa-instagram:hover {
color: #fbad50;
}
#eind ul {
padding: 0px;
}
#eind p {
margin-bottom: 100px;
}
.button {
background-color: #faebd7 !important;
color: #666 !important;
}
#mc_embed_signup {
width: 40%;
margin: 0 auto;
}
#mc_embed_signup .mc-field-group input {
border: 0px !important;
border-radius: 0px !important;
border-bottom: 2px solid #666666 !important;
}
#mc_embed_signup #mc-embedded-subscribe-form input.mce_inline_error {
border: 0px !important;
border-radius: 0px !important;
border-bottom: 2px solid #e85c41 !important;
}
#mc_embed_signup_scroll {
text-align: center;
}
textarea:focus,
input:focus {
outline: none;
}
#mc_embed_signup h2 {
margin-bottom: 10% !important;
}
.clear {
width: 150px;
margin: 0 auto;
margin-top: 5%;
}
.clear #mc-embedded-subscribe {
border-radius: 0px !important;
width: 150px !important;
margin: 0 auto !important;
height: 50px !important;
}
/*animation element*/
.animation-element {
position: relative;
}
/*bounce up animation for the subject*/
.bounce-up {
opacity: 0;
-moz-transition: all 700ms ease-out;
-webkit-transition: all 700ms ease-out;
-o-transition: all 700ms ease-out;
transition: all 700ms ease-out;
-moz-transform: translate3d(0px, 200px, 0px);
-webkit-transform: translate3d(0px, 200px, 0px);
-o-transform: translate(0px, 200px);
-ms-transform: translate(0px, 200px);
transform: translate3d(0px, 200, 0px);
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
}
.bounce-up.in-view {
opacity: 1;
-moz-transform: translate3d(0px, 0px, 0px);
-webkit-transform: translate3d(0px, 0px, 0px);
-o-transform: translate(0px, 0px);
-ms-transform: translate(0px, 0px);
transform: translate3d(0px, 0px, 0px);
}
#media (max-width: 1440px) {
#disclaimer {
position: relative;
left: 48%;
bottom: 10px;
}
}
#media (max-width: 1024px) {
#image-1 img {
position: relative;
left: -244px;
}
}
#media (max-width: 768px) {
.video {
margin-top: 30%;
}
#introductie-1 .text-container {
width: 280px;
}
#image-1-container #image-1 {
width: 35%;
}
#mc_embed_signup {
width: 60%;
}
}
#media (max-width: 430px) {
.sign-up-banner {
position: sticky;
top: 0px !important;
max-height: 325px;
}
.desktop-only {
display: none;
}
#disclaimer {
left: 42%;
}
.mobile-only {
display: inherit;
}
.coming-soon h1 {
font-size: 45px;
}
.sign-up-banner {
height: 60%;
}
#introductie-1 {
height: 250%;
}
#introductie-2 {
max-height: 500px;
height: 200%;
}
#release {
opacity: 1;
}
.left,
.right {
width: 100%;
}
#introduction-1-container {
height: 100%;
}
#introductie-1 #image-1 {
display: none;
}
#introductie-2 #image-2 {
display: none;
}
#introductie-2 .text-container {
width: 80%;
text-align: center;
margin: 0 auto;
}
#introductie-1 .text-container {
position: initial;
width: 80%;
margin: 0 auto;
text-align: center;
margin-top: 40px;
}
#coming-soon h1 {
font-size: 24px;
}
#introductie-1 .text-container p {
font-size: 1.2em;
}
#introductie-2 p {
font-size: 1.2em;
}
.video {
margin-top: 60%;
}
.social-media ul {
padding: 0px;
}
#mc_embed_signup {
width: 100%;
margin: 0 auto;
}
#text-1 {
opacity: 1 !important;
}
#text-2 {
position: initial !important;
opacity: 1 !important;
}
#eind {
height: 120%;
max-height: 1000px;
}
.eind-block {
position: relative;
}
.fa-balance-scale {
padding: 40px 34px;
}
}
#media (max-width: 320px) {
#coming-soon h1 {
font-size: 24px;
}
#introductie-1 .text-container p {
font-size: 1.2em;
}
#introductie-2 p {
font-size: 1.2em;
}
.video {
margin-top: 60%;
}
.social-media ul {
padding: 0px;
}
#mc_embed_signup {
width: 100%;
margin: 0 auto;
}
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0" />
<title>Volks</title>
<link rel="stylesheet" href="styles/index.processed.css">
<script src="https://use.fontawesome.com/39f17a3ca2.js"></script>
</head>
<body>
<section class="video-section">
<div class="video">
<video loop autoplay id="video-background" muted playsinline>
<source src="http://rapio.nl/videos/teaser.mp4" type="video/mp4">
</video>
</div>
</section>
<section id="coming-soon">
<div class="align-center center-text coming-soon">
<h1 class="">Binnenkort verkrijgbaar.</h1>
</div>
</section>
<section class="sign-up-banner">
<!-- Begin MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
<style type="text/css">
#mc_embed_signup {
background: #fff;
clear: left;
font: 14px Helvetica, Arial, sans-serif;
}
/* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>
<div id="mc_embed_signup">
<form action="https://volksphone.us17.list-manage.com/subscribe/post?u=e0b25e148103e039f3ed554d1&id=bbad48d887" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll">
<h2>Ontvang een notificatie bij de bekendmaking van onze crowdfundings-campagne.</h2>
<div class="mc-field-group">
<input type="email" placeholder="Emailadres" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div>
<div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_e0b25e148103e039f3ed554d1_bbad48d887" tabindex="-1" value=""></div>
<div class="clear"><input type="submit" value="verzend" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
</form>
</div>
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script>
<script type='text/javascript'>
(function($) {
window.fnames = new Array();
window.ftypes = new Array();
fnames[0] = "EMAIL";
ftypes[0] = "email";
fnames[1] = "FNAME";
ftypes[1] = "text";
fnames[2] = "LNAME";
ftypes[2] = "text";
fnames[3] = "BIRTHDAY";
ftypes[3] = "birthday";
})(jQuery);
var $mcj = jQuery.noConflict(true);
</script>
<!--End mc_embed_signup-->
</section>
<section class="introductie" id="introductie-1">
<div class="container" id="introduction-1-container">
<div class="left" id="image-1-container">
<div class="image-container " id="image-1">
<img src="media/image-1.jpg">
</div>
</div>
<div class="right">
<div class="text-container" id="text-1">
<div class="icon mobile-only"><img class="nederland-icon" src="media/nederland_icoon.png"></div>
<h1>Van Nederlandse Bodem</h1>
<p>Volks is een Amsterdamse startup achter de eerste Nederlandse high-end smartphone. Maak kennis met onze technologie, je zult verrast zijn.</p><br><br>
<div class="icon mobile-only"><i class="fa fa-balance-scale mobile-only fa-icon" aria-hidden="true"></i></div>
<h1>Balans tussen prijs en kwaliteit</h1>
<p class="mobile-only">Wanneer had je voor het laatst een smartphone in je handen? Precies, nu.</p><p>Wanneer had je voor het laatst een smartphone in je handen? Precies, nu.</p><p>Er is een overvloed aan smartphones. Helaas betaal je nog steeds de hoogste prijs, of iets minder maar ontbreekt goede ondersteuning en kwaliteit. Volks wilt een balans bieden tussen een eerlijke prijs, goede customer support en topkwaliteit.
</p><br><br>
<div class="icon mobile-only"><i class="fa fa-users fa-icon" aria-hidden="true"></i></div>
<h1 class=" mobile-only">En nu voor iedereen</h1>
<p class=" mobile-only">Het is bijna zover. Binnenkort start de crowdfunding-campagne en hier hebben we jouw hulp hard bij nodig. Tijdens deze campagne kom je in de gelegenheid een pre-order te plaatsen. Slechts een gelimiteerd aantal Volks toestellen zijn beschikbaar tijdens de voorverkoop.
</p>
</div>
</div>
</div>
</section>
<section class="introdcutie desktop-only" id="introductie-2">
<div class="text-container" id="text-2">
<div class="icon mobile-only"><i class="fa fa-users fa-icon" aria-hidden="true"></i></div>
<h1>En nu voor iedereen</h1>
<p>Het is bijna zover. Binnenkort start de crowdfunding-campagne en hier hebben we jouw hulp hard bij nodig. Tijdens deze campagne kom je in de gelegenheid een pre-order te plaatsen. Slechts een gelimiteerd aantal Volks toestellen zijn beschikbaar tijdens de voorverkoop.
</p>
</div>
<div class="image-container " id="image-2">
<img src="media/image-2.png">
</div>
</section>
<section id="eind">
<div class="align-center center-text coming-soon eind-block">
<p>Meer info over de datum en technische specificaties volgt binnenkort op onze Facebookpagina.</p>
<h1 class="">Volks<i class="fa fa-copyright" aria-hidden="true" style="font-size:15px;"></i> <br> December 2017</h1>
<div class="social-media">
<ul>
<li>
<i class="fa fa-facebook" aria-hidden="true"></i>
</li>
<li>
<i class="fa fa-instagram" aria-hidden="true"></i>
</li>
</ul>
</div>
</div>
</section>
<a id="disclaimer" href="disclaimer.html">disclaimer</a>
<!-- ==== scripts ==== -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.16.0/TweenMax.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.3/ScrollMagic.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.3/plugins/animation.gsap.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.2/plugins/debug.addIndicators.min.js'></script>
<!-- ==== CUSTOM JS ==== -->
<script src="scripts/index.js"></script>
</body>
</html>
It's not matter of IOS, it's matter of responsiveness. You have set fixed height to each section so it is overlapping with each others on mobile devices.
Just set all section height to height: 100vh.
And
#media (max-width: 430px){
.introductie {
height: 300vh;
overflow: hidden;
}
}
It should works.
I've Found my answer.
It was a JS script that automaticly finds the height of the window and sets that height to a given class.
But, that wasn't the whole solution. The height's where better, and weren't all over the place as it was before when I applied height:100%; to the html, body and section.
I made media queries, on the max-height per phone size, so it was expand beyond the intended sections.
https://90c726a539a841eb97f1b7b3f2aaf646.codepen.website
The JS solution is:
// On document ready set the div height to window
$(document).ready(function(){
// Assign a variable for the application being used
var nVer = navigator.appVersion;
// Assign a variable for the device being used
var nAgt = navigator.userAgent;
var nameOffset,verOffset,ix;
// First check to see if the platform is an iPhone or iPod
if(navigator.platform == 'iPhone' || navigator.platform == 'iPod'){
// In Safari, the true version is after "Safari"
if ((verOffset=nAgt.indexOf('Safari'))!=-1) {
// Set a variable to use later
var mobileSafari = 'Safari';
}
}
//===== FULL HEIGHT =====\\
// If is mobile Safari set window height +60
if (mobileSafari == 'Safari') {
// Height + 60px
$('.full-height').css('height',(($(window).height()) + 60)+'px');
} else {
// Else use the default window height
$('.full-height').css({'height':(($(window).height()))+'px'});
};
});
// On window resize run through the sizing again
$(window).resize(function(){
// If is mobile Safari set window height +60
if (mobileSafari == 'Safari') {
// Height + 60px
$('.full-height').css('height',(($(window).height()) + 60)+'px');
} else {
// Else use the default window height
$('.full-height').css({'height':(($(window).height()))+'px'});
};
/* //===== HALF HEIGHT =====\\
// If is mobile Safari set window height +60
if (mobileSafari == 'Safari') {
// Height + 60px
$('.half-height').css('min-height',(($(window).height() /2) + 60)+'px'/2);
} else {
// Else use the default window height
$('.half-height').css({'min-height':(($(window).height()/2) )+'px'});
};
// On window resize run through the sizing again
$(window).resize(function(){
// If is mobile Safari set window height +60
if (mobileSafari == 'Safari') {
// Height + 60px
$('.half-height').css('min-height',(($(window).height()/ 2) + 60)+'px');
} else {
// Else use the default window height
$('.half-height').css({'min-height':(($(window).height()/ 2) )+'px'});
};
});
//===== DOUBLE HEIGHT =====\\
// If is mobile Safari set window height +60
if (mobileSafari == 'Safari') {
// Height + 60px
$('.half-height').css('min-height',(($(window).height()* 2) + 60)+'px');
} else {
// Else use the default window height
$('.half-height').css({'min-height':(($(window).height()* 2) )+'px'});
};
});
// On window resize run through the sizing again
$(window).resize(function(){
// If is mobile Safari set window height +60
if (mobileSafari == 'Safari') {
// Height + 60px
$('.half-height').css('min-height',(($(window).height()* 2) + 60)+'px');
} else {
// Else use the default window height
$('.half-height').css({'min-height':(($(window).height()* 2) )+'px'});
};*/
});
And the CSS (used SCSS) solution is:
//IPHONE&SAMSUNG PLUS
#media (max-height: 736px) {
.full-height{
max-height:736px;
}
.introductie-mobile {
height: 1200px !important;
max-height: 1200px;
}
}
//IPHONE 6/7/8
#media (max-height: 667px) {
.full-height{
max-height:667px;
}
.introductie-mobile {
height: 1200px !important;
max-height: 1200px;
}
}
//IPHONE %
#media (max-height: 568px) {
.full-height{
max-height:568px;
}
.introductie-mobile {
height: 1200px !important;
max-height: 1200px;
}
}
The height of the top black <div class="video-section"> is full height on any device including iPhone. So height in and of itself is not the problem.
On other devices however, the position of the next <div class="sign-up-banner"> changes dynamically so that it moves with a parallax effect as you scroll down. Once you're fully past the top black <div class="video-section"> the entire second <div class="sign-up-banner"> is fully visible. This is being done with the javascript code. For whatever reason, this javascript is not running on the iPhone.
Some of the CSS applied to the <form> within the <div id="coming-soon"> is still applied which leaves you with the div stuck behind the first one.
You can reverse this with the following css:
.sign-up-banner{
position: static;
height: auto;
}
#mc_embed_signup form{
position: static !important;
-ms-transform: none; /* IE 9 */
-webkit-transform: none; /* Chrome, Safari, Opera */
transform: none;
}
You could wrap that in a media query so it only applies to a particular screen. To get it to apply for the iPhone.
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2) {
//insert your css here
}
That will apply css to a iPhone 4 and 4s. It's not guaranteed to not apply to other devices, but css cannot target particular devices so it's the best we've got. You can see media queries which target other devices including other iPhone models at https://css-tricks.com/snippets/css/media-queries-for-standard-devices/.
I have two horizontally aligned responsive divs that are set to be the same height.
The left holds an embedded youtube video, the right a fixed image.
Tested in Chrome there are no issues, but if tested in Safari the youtube video is not filling the full height of the div.
html markup is:
<div id="IndexBanners">
<div class="indexbannerimages effect first">
<div id="player"></div>
<script src="https://www.youtube.com/player_api"></script>
<script>
// create youtube player
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
videoId: 'GfaiXgY114U',
autoplay: '0',
controls: '0',
width: '100%',
height: '100%',
playerVars: {
rel: 0,
showinfo: 0
},
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// autoplay video
function onPlayerReady(event) {
// event.target.playVideo();
}
// change mask opacity depending on player state
function onPlayerStateChange(event) {
if (event.data === -1) {
document.getElementById("mask1").setAttribute("style", "opacity:1; -moz-opacity:1; filter:alpha(opacity=100)");
}
if (event.data === 0) {
document.getElementById("mask1").setAttribute("style", "opacity:1; -moz-opacity:1; filter:alpha(opacity=100)");
}
if (event.data === 1) {
document.getElementById("mask1").setAttribute("style", "opacity:0; -moz-opacity:0; filter:alpha(opacity=0)");
}
if (event.data === 2) {
document.getElementById("mask1").setAttribute("style", "opacity:1; -moz-opacity:1; filter:alpha(opacity=100)");
}
}
</script>
<div id="mask1">
<div class="watchText">Watch The Video</div>
<div class="watch"></div>
</div>
</div>
<div class="indexbannerimages effect">
<img src="https://placehold.it/795x436">
<div id="mask2">
<div class="newsText">Latest News</div>
<div class="news"></div>
</div>
</div>
</div>
css:
#IndexBanners {
display: flex;
margin-top: 20px;
}
.indexbannerimages {
flex: 1 0 0;
position: relative;
}
img {
max-width: 100%;
height: auto;
vertical-align: top;
}
.indexbannerimages .watch {
background: url(../images/play-icon.png) no-repeat scroll 0% 25% / 14px auto;
}
.indexbannerimages .news {
background: url(../images/news-icon.png) no-repeat scroll 0% 25% / 14px auto;
}
.watchText {
color: #fff;
text-transform: uppercase;
padding-top: 23%;
margin: 0;
}
.newsText {
color: #fff;
text-transform: uppercase;
padding-top: 23%;
margin: 0;
}
.effect #mask1,
.effect #mask2 {
text-align: center;
font-size: 16px;
color: #fff;
background-color: rgba(00, 00, 00, 0.8);
opacity: 0.75;
transition: all 0.5s ease-in-out;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
cursor: pointer;
}
.effect:hover #mask1,
.effect:hover #mask2 {
visibility: hidden;
opacity: 0.0;
transition: all 0.5s ease-in-out;
}
#media (max-width:600px) {
#IndexBanners {
display: block;
}
.first {
position: relative;
padding-bottom: 56.25%;
height: 0;
}
.first iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
I've set up a fiddle here to demonstrate the issue. https://jsfiddle.net/bgaqfvxm/3/
Any suggestions on a fix for this size issue in Safari?
Issue resolved by adding the following to the css
.first iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Thanks to #Michael Coker for the original css that was used in #media query below 600px