我的网站上有一个按钮,点击它会显示/隐藏谷歌地图 div(使用 iframe 嵌入)。除了 border-radius 仅在 jquery animate 期间工作外,它工作正常。动画完成后,iframe 变为正方形。
HTML
<div id="layer-2">
<span id="moreInfo">
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d12242.306455925878!2d-75.12138282383809!3d39.90611059880662!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x3e48fdca1ebac4d0!2sWalt+Whitman+Bridge!5e0!3m2!1sen!2sin!4v1395728987250" width="300" height="200" frameborder="0" style="border:0"></iframe>
</span>
</div>
<button>Show</button>
Javascript
$(function () {
$("button").on("click", function () {
if(parseInt($("#moreInfo").css("opacity"))) {
$("button").text("Show");
$("#moreInfo").css({opacity:1,top:0,height:200,display:'inline'});
$("#moreInfo").animate({opacity: 0,top: 100,height: 100}, 100, function () {$("#moreInfo").hide();});
} else {
$("button").text("Hide");
$("#moreInfo").css({opacity:0,top:100,height:100,display:'inline'});
$("#moreInfo").show();
$("#moreInfo").animate({opacity: 1,top: 0,height: 200}, 100);
}
});
});
CSS
#moreInfo {
position: absolute;
opacity: 0;
top: 0px;
left: 10px;
width: 300px;
height: 200px;
background-color: blue;
border-radius: 50%;
}
#layer-2 {
height: 200px;
}
body {
background-color: #aaa;
}
Note: Please don't mark this duplicate, I have gone through a number of stack overflow answers, but none of them helped. Also please don't suggest for any other google maps api integration, I need to use the iFrame implementation.
最佳答案
它确实有效,您需要为 span
元素使用 overflow: hidden;
作为您的 iframe
溢出 span
元素,并且由于您没有在 iframe 上应用 border-radius
,它呈现为矩形 block ...
#moreInfo {
position: absolute;
opacity: 0;
top: 0px;
left: 10px;
width: 300px;
height: 200px;
background-color: blue;
border-radius: 50%;
overflow: hidden;
}
如果您不想为父级使用 overflow: hidden;
,请为 iframe
使用 border-radius
作为好吧...并摆脱 blue
background color...
#moreInfo iframe {
border-radius: 50%;
}
Demo 2 (作为 you commented,在 Chrome 上失败,将很快调查)
关于javascript - 嵌入谷歌地图的 iFrame 上的 CSS 边框半径不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22627311/