我有一个网站,需要在每个屏幕上全屏显示。因此,我使用大量 jQuery 来确定高度、最大高度、边距……
我在容器 ID 上有一个 margin-top 。当我在脚本末尾调用高度(这是确定边距顶部的基础)时,它没有给我正确的数量。
只要varcontainerh中容器id的高度不正确,varcontainert也不会正确。
var height = $(window).height();
var width = $(window).width();
var containerw = width * 0.9;
var containerl = containerw * 0.5;
var containerh = $("#container").height();
var containert = containerh * 0.5;
$("#container").css("margin-left", "-" + containerl + "px");
$("#container").css("margin-top", "-" + containert + "px");
alert($("#container").height());
* {
margin: 0;
padding: 0;
overflow: hidden;
}
h1 {
font-family: 'Hobo';
color: #0070c0;
font-weight: lighter;
}
font {
color: #ed27b9;
}
#container {
position: absolute;
top: 46%;
left: 50%;
}
video {
border: 2px solid #134963;
}
<center>
<div id="container">
<center>
<h1>Leur <font>« experience »</font> en quelques mots...</h1>
</center>
<center id="boven">
<video class="video2" frameborder="0" poster="../beelden/image39.png" webkitAllowFullScreen mozallowfullscreen allowFullScreen controls>
<source src="../video/film1.mp4" type="video/mp4">
<source src="../video/film1.ogg" type="video/ogg">
<source src="../video/film1.webm" type="video/webm">
Your browser does not support the video tag
</video>
<video class="video2" frameborder="0" poster="../beelden/image40.png" webkitAllowFullScreen mozallowfullscreen allowFullScreen controls>
<source src="../video/film1.mp4" type="video/mp4">
<source src="../video/film1.ogg" type="video/ogg">
<source src="../video/film1.webm" type="video/webm">
Your browser does not support the video tag
</video>
</center>
任何人都可以帮我解决容器的边距顶部和高度吗?它在我的屏幕上返回 552px,但容器 id 的高度是 546px
我有什么example
最佳答案
使用
$("#element").outerHeight();
或
$("#element").innerHeight();
根据您的要求。
关于javascript - jQuery .height() 不返回正确的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30663633/