我正在做一个小测试,点击显示 iframe 的图像。然后我想单击除该图像(#container div)之外的任何位置。我可以让 iframe 弹出,但是当我单击主 div (#container) 时无法隐藏它。
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script>
$(function() {
var moveLeft = 20;
var moveDown = 10;
$('a#trigger').click(function(e) {
$('div#pop-up').show();
//.css('top', e.pageY + moveDown)
//.css('left', e.pageX + moveLeft)
//.appendTo('body');
}, function() {
$('#container').click(function(){
$('div#pop-up').hide();
});
$('a#trigger').mousemove(function(e) {
$("div#pop-up").css('top', e.pageY + moveDown).css('left', e.pageX + moveLeft);
});
});</script>
<style>
h1{
margin: 0;
padding: 0;
font-weight: normal;
}
div#container {
width: 580px;
margin: 15px auto 0 auto;
padding: 20px;
background: #000;
border: 1px solid #1a1a1a;
}
/* HOVER STYLES */
div#pop-up {
display: none;
position: absolute;
/*width: 150px;
padding: 150px;*/
background: #eeeeee;
color: #000000;
border: 1px solid #1a1a1a;
font-size: 90%;
}
</style>
</head>
<body>
<div id="container">
<h1>Pop-out Example - pop out div on hover</h1>
<p>
<a href = "#" id="trigger"><img src="router.png"/></a>
</p>
</div>
<div id="pop-up">
<p>
<iframe width="500px" height="350px" align= "top-left" src="http://127.0.0.1:667"></iframe>
</p>
</div>
</body>
</html>