[英]div with iframe in it, display none
I have a page where I am displaying a iframe from another page.我有一个页面,我在其中显示来自另一个页面的 iframe。 I want that iframe to be display:none at load and become visible onClick.
我希望 iframe 在加载时显示:无并在单击时可见。 The issue is, I can get it to work if the div is visible at load.
问题是,如果 div 在加载时可见,我可以让它工作。 If it is hidden at load, the onclick doesnt work properly.
如果它在加载时隐藏,则 onclick 无法正常工作。
<script>
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
<div style="margin-top:30px;">
<h2>Menu</h2>
<p>Dayton, Ohio Menu Coming Soon. It can be viewed currently at <a href="https://www.leafly.com/dispensary-info/pure-ohio-wellness" target="_blank" style="color:green">here</a></p>
<p><a onClick="myFunction()">Springfield, Ohio Menu</a></p>
<div>
<div id="myDIV" style="display: none">
<div id="leafly-menu">
</div>
<div style="text-align:center;">
</div>
<script src="https://www.leafly.com/public/global/js/dispensarymanager/embed.js"></script>
<script>var pymParent = pym.Parent('leafly-menu', 'https://www.leafly.com/embed/menu2/pure-ohio-wellness---springfield', {});</script>
</div>
<div style="overflow: hidden; margin: 15px auto; max-width: 975px;display: none;">
<iframe scrolling="no" src="https://www.leafly.com/dispensary-info/pure-ohio-wellness---springfield" style="border: 0px none; margin-left: -36px; height: 1012px; margin-top: -486px; width: 1050px;">
</iframe>
</div>
</div>
</div>
I think the functionality you're looking for here can be solved with the visibility:hidden tag, as I've had similar experienced with the "display:none" css property.我认为您在这里寻找的功能可以通过可见性:隐藏标签来解决,因为我对“display:none”css 属性有过类似的经历。
Definitely worth another google for differences between the two, but thew3schools snippet here seems to summarize things pretty well.对于两者之间的差异,绝对值得另一个谷歌,但这里的w3schools片段似乎很好地总结了事情。
Hope this helps!希望这可以帮助!
You can easily display the elements inside the Div using the click()
function of jQuery.您可以使用 jQuery 的
click()
函数轻松地显示 Div 内的元素。 You need to include the jQuery CDN or jQuery file to run the jQuery scripts.您需要包含 jQuery CDN 或 jQuery 文件才能运行 jQuery 脚本。
$(document).ready(function() { $("#showMe").click(function () { $("#myDIV").show(); }) });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <div style="margin-top:30px;"> <h2>Menu</h2> <p>Dayton, Ohio Menu Coming Soon. It can be viewed currently at <a href="https://www.leafly.com/dispensary-info/pure-ohio-wellness" target="_blank" style="color:green">here</a></p> <p><a id = "showMe" href="#">Springfield, Ohio Menu</a></p> <div id="myDIV" style="display: none"> <div > <div id="leafly-menu"> </div> <div style="text-align:center;"> </div> <script src="https://www.leafly.com/public/global/js/dispensarymanager/embed.js"></script> <script>var pymParent = pym.Parent('leafly-menu', 'https://www.leafly.com/embed/menu2/pure-ohio-wellness---springfield', {});</script> </div> <div style="overflow: hidden; margin: 15px auto; max-width: 975px;"> <iframe scrolling="no" src="https://www.leafly.com/dispensary-info/pure-ohio-wellness---springfield" style="border: 0px none; margin-left: -36px; height: 1012px; margin-top: -486px; width: 1050px;"> </iframe> </div> </div> </div>
I have updated the Fiddle with the two menus.我已经用两个菜单更新了小提琴。 https://jsfiddle.net/9b15gw0f/
https://jsfiddle.net/9b15gw0f/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.