加载脚本时修改div的高度

时间:2019-03-06 16:06:39

标签: javascript jquery html css

我有一个使用Bootstrap和Flask构建的Web应用程序,它将Bokeh服务器文档加载到包含div的文件中。散景元素大小调整的响应行为取决于包含div的特定固定初始高度。我在包含自定义CSS的style.css文件中执行此操作:

.placeholderbokehapp {
  height: 1500px;
}

在散景内容加载后,我想立即将.placeholderbokehapp的高度增加到1700px,以容纳其他元素。在Chrome DevTools的“网络”标签中,我看到Bokeh内容加载了autoload.js?bokeh-autoload-element=...脚本,紧接着是jquery和其他所需的js。

以下是base.html中的相关内容:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

  <title>{% block title %}Snowpack Tracker{% endblock %}</title>

  <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

  <link
    href="https://cdn.pydata.org/bokeh/release/bokeh-1.0.4.min.css"
    rel="stylesheet" type="text/css">
  <link
    href="https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.4.min.css"
    rel="stylesheet" type="text/css">

  <script src="https://cdn.pydata.org/bokeh/release/bokeh-1.0.4.min.js"></script>  
  <script src="https://cdn.pydata.org/bokeh/release/bokeh-widgets-1.0.4.min.js"></script> 

</head>

<body>

  <div class="container-fluid">
    {% block header %}{% endblock %}

    {% block content %}{% endblock %}

    {% block footer %}{% endblock %}

  </div>

  <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

</body>
</html>

使用Flask,我渲染以下模板:

{% extends 'base.html' %}

{% block header %}
{% include 'snowpacktracker/header.html' %}
{% endblock %}

{% block content %}
  <div class="placeholderbokehapp rounded" id="tbc-id">
        {{ wholebokehapp | safe }}
  </div>

{% endblock %}

{% block footer %}
{% include 'snowpacktracker/footer.html' %}
{% endblock %}

wholebokehapp是从URL返回的Bokeh嵌入式服务器文档。

2 个答案:

答案 0 :(得分:1)

您可以这样做,但是可能有更好的方法

$($('.placeholderbokehapp').css('height', '1700px'))

答案 1 :(得分:1)

如果Bokeh正在iframe html标记中加载,则可以在html页面底部加载所有其他js脚本之后编写脚本。

<script>
    $('#tbc-id iframe').load(function(){
        $('#tbc-id').css({height: 1700}) //make container height to 1700px        
       $(this).css({height: 1700}) //make iframe height match the container

    });
</script>