summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-values/support/vh_not_refreshing_on_chrome_iframe.html
blob: 8d8e9b49d4aa3d9804a176852288e32ccaaa47d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<!-- Submitted from TestTWF Paris -->
<head>

	<title>CSS Values and Units Test: vh-based dimension doesn't change when the element other dimension doesn't change.</title>

	<style type="text/css">

		* { margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; font-size: 13px; }

			/* the first test box has its vertical dimension is set to some vh units */
		#testBoxWithVhOnly { background: #F00; width: 60px; height: 20vh; float: left; }

			/* the second test box, with fixed height */
		#testBoxNotGrownHorizontallyByJS { background: #F0F; width: 20vh; height: 60px; float: left; }

			/* third box, changed by using CSS transition */
		#testBoxWithTransition { background: #FF0; width: 20vh; height: 40px; float: left;
			transition-property:       width, height;
			transition-duration:       0.3s;
			transition-delay:          0;
		}

			/* the reference box, growing in both directions (height by js, width by vh unit */
		#referenceBoxGrownHorizontallyByJS { background: #0F0; width: 20vh; height: 40px; float: left; }

		p { clear: both; margin: 10px 0; }

	</style>

</head>
<body>

<p>
	All boxes should end up the same size. The green box is the reference one.
</p>

<div id="testBoxWithVhOnly"></div>
<div id="testBoxNotGrownHorizontallyByJS"></div>
<div id="testBoxWithTransition"></div>
<div id="referenceBoxGrownHorizontallyByJS"></div>

<script type="text/javascript">
	'use strict';

	// In case this file was opened by mistake, redirects to proper test
	if (window.top.location.href  === document.location.href) {

		window.top.location.href = "vh_not_refreshing_on_chrome.html";

	}

	function setDimension(id, dimension, value) {

		var element = document.getElementById(id);

		element.style[dimension] = value + "px";

	}

	function animate() {

		var viewportHeight = document.documentElement.clientHeight;

		var sizeH = 20;

		var referenceDimension = Math.round(sizeH * viewportHeight / 100);

		setDimension('referenceBoxGrownHorizontallyByJS', 'height', referenceDimension);

		if (referenceDimension < 60) {
			setTimeout(animate, 20);
		} else {
			parent.postMessage('referenceBoxGrownHorizontallyByJS', '*');
		}
	}

	setTimeout(animate, 20);

	addEventListener('transitionend', event => {
		if (event.propertyName == 'width') {
			// Stop any further transitons.
			testBoxWithTransition.style.transitionProperty = 'none';
			parent.postMessage('testBoxWithTransition', '*');
		}
	}, false);
	var transitionedTestBoxStyle = document.getElementById('testBoxWithTransition').style;
	transitionedTestBoxStyle.height = "60px";
</script>

</body>
</html>