简体   繁体   English

加载脚本时修改 div 高度

[英]modify div height when script loaded

I have a web app built with Bootstrap and Flask that loads a Bokeh server document into a containing div.我有一个使用 Bootstrap 和 Flask 构建的 Web 应用程序,它将Bokeh服务器文档加载到包含的 div 中。 The responsive behavior of the sizing of the Bokeh elements depends on a specific fixed initial height for the containing div. Bokeh 元素大小的响应行为取决于包含 div 的特定固定初始高度。 I do this in a style.css file that contains my custom css:我在包含我的自定义 css 的style.css文件中执行此操作:

.placeholderbokehapp {
  height: 1500px;
}

Immediately after the Bokeh content loads I would like to increase the height of .placeholderbokehapp to 1700px to accommodate additional elements.在 Bokeh 内容加载后,我想立即将.placeholderbokehapp的高度.placeholderbokehapp 1700px 以容纳其他元素。 In the Chrome DevTools Network tab, I see the Bokeh content loaded with an autoload.js?bokeh-autoload-element=... script, immediately followed by jquery and other needed js.在 Chrome DevTools Network 选项卡中,我看到 Bokeh 内容加载了autoload.js?bokeh-autoload-element=...脚本,紧接着是 jquery 和其他需要的 js。

Here is the relevant content in base.html :下面是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.bokeh.org/bokeh/release/bokeh-1.0.4.min.css"
    rel="stylesheet" type="text/css">
  <link
    href="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-1.0.4.min.css"
    rel="stylesheet" type="text/css">

  <script src="https://cdn.bokeh.org/bokeh/release/bokeh-1.0.4.min.js"></script>  
  <script src="https://cdn.bokeh.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>

Using Flask, I render the following template:使用 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 is the Bokeh embedded server document that is returned from a URL. wholebokehapp是从 URL 返回的 Bokeh 嵌入式服务器文档。

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

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

if the Bokeh is loading within an iframe html tag then you can write a script after loading all other js scripts at the bottom of html page.如果 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM