jQuery .height()没有返回正确的值 [英] jQuery .height() doesn't return the right value

查看:86
本文介绍了jQuery .height()没有返回正确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,需要在每个屏幕上全屏显示.因此,我使用很多jQuery来确定高度,最大高度,边距,...

I have a website that needs to be fullscreen at every screen. For this reason I use alot of jQuery to determin the height, max-height, margins, ...

我在容器ID上有一个页边空白.当我在脚本末尾调用高度(这是确定边距顶部的基础)时,它给我的金额不正确.

I have a margin-top on the container id. When i call the height, which is the base of determing the margin-top, at the end of the script, it does not give me the right amount.

只要在var containerh中容器id的高度不正确,var容器t也将不正确.

As long as the height of the container id is not right in var containerh, var containert will not be right either.

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>&#171; experience &#187;</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

Can anyone help me with the margin-top and height of the container? It returns 552px at my screen, but the height of the container id is 546px

我有什么示例

推荐答案

使用

$("#element").outerHeight();

$("#element").innerHeight();

根据您的要求.

这篇关于jQuery .height()没有返回正确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆