该脚本适用于Chrome,Opera和Internet Explorer。
据我所知,我使用的所有方法都与Firefox兼容。
div #togg 应该会在您点击 #father div时显示,但这不适用于Firefox。
如果您发现错误,请告诉我?
https://jsfiddle.net/8Lpze23p/
function where() {
// Declare variables
var togg = document.getElementById("togg");
// Detect coordinates
var euX = event.clientX;
var euY = event.clientY;
// Set position
togg.style.left = euX + "px";
togg.style.top = euY + "px";
// Set ClassName
togg.className = "toggInfoShow";
// Get result
//var myTime = setTimeout (function(){ togg.className = "toggInfoHide";}, 3000);
document.getElementById("result").innerHTML = myTime;
}
function closeit() {
document.getElementById("result").innerHTML = "closed";
var togg = document.getElementById("togg");
togg.className = "toggInfoHide";
}
#father {
height: 500px;
width: 500px;
background: #b4b4b4;
}
.toggInfoShow {
padding: 10px;
position: fixed;
top: 50px;
left: 50px;
height: 115px;
width: 225px;
background: #d2d2d2;
display: block;
}
.toggInfoHide {
display: none;
}
#closeThis {
background: #434343;
color: #f3f3f3;
padding: 6px;
cursor: pointer;
width: 25px;
height: 25px;
}
<div id="father" onclick="where()" onmouseleave="closeit()">
<div id="togg">
</div>
<h3 id="result"></h3>
</div>