简体   繁体   English

HTML5不会加载隐藏的div吗?

[英]HTML5 doesn't load a hidden div?

I want to make a toggle-able chart and everything works fine if it starts off with the chart is visible. 我想制作一个可切换的图表,如果从图表开始就可见,那么一切工作正常。 However, if I use display: none and then toggle, the chart doesn't show the actual candlesticks bars and I can't figure out why. 但是,如果我使用display: none然后切换,则该图表不会显示实际的烛台图,因此我无法弄清楚原因。

Supposed to be: 应该是:

应该是

Here is my code: 这是我的代码:

CodePen CodePen

 var chart = new cryptowatch.Embed('bitfinex', 'btcusd', { timePeriod: '1d', width: 650, customColorScheme: { bg: "000000", text: "b2b2b2", textStrong: "e5e5e5", textWeak: "7f7f7f", short: "FD4600", shortFill: "FF672C", long: "6290FF", longFill: "002782", cta: "363D52", ctaHighlight: "414A67", alert: "FFD506", } }); chart.mount('#chart-container'); $('#btn').click(function() { $('#chart-container').toggle(200); }); 
 html { display: flex; justify-content: center; text-align: center; } #chart-container { width: 100%; height: 400px; display: none; } #btn { font-size: 2em; width: 200px; border: black 2px solid; padding: 2px 0; cursor: pointer; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="chart-container"></div> <div id="btn">click</div> <script type="text/javascript" src="https://static.cryptowat.ch/assets/scripts/embed.bundle.js"></script> 

Please comment out display: none , you will see what I mean. 请注释掉display: none ,您将明白我的意思。

You can simply use "getElementById()" function of javascript instead of using "display: none" property of css. 您可以简单地使用javascript的“ getElementById()”函数,而不是使用CSS的“ display:none”属性。

For Example: 例如:

<div id="myDiv"></div>
document.getElementById("myDiv").innerHTML = "Div changed!";

Hopefully this will works fine. 希望这会很好。 Thank you :) 谢谢 :)

If you add a wrapper to the chart-container and then toggle ie its height it will work. 如果将wrapper添加到chart-container ,然后切换(即其高度),它将起作用。

Updated codepen 更新的代码笔

HTML HTML

<div id="container">
  <div id="chart-container"></div>
</div>

CSS CSS

#container {
  width: 100%;
  height: 0;
  overflow: hidden;
}
#container.show {
  height: 400px;
}

JS JS

$('#btn').click(function(){
  $('#container').toggleClass('show');
});

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

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