简体   繁体   中英

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. The responsive behavior of the sizing of the Bokeh elements depends on a specific fixed initial height for the containing div. I do this in a style.css file that contains my custom 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. 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.

Here is the relevant content in 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:

{% 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.

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

$($('.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.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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