스팬을 몇 초 동안 가져 가면 상자가 나타나고 상자에 마우스를 올려 놓으면 다시 페이드 아웃하지 않고 그대로 서있는 코드를 만들려고합니다. 샘플 코드는이 하나두 번째로 요소 위로 마우스를 가져 가면 왜 사라지나요?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>I'm a pathetic programmer please don't flame me</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
$(function() {
var b = 1000;
var c = $('#box');
var d = function(a) {
if (a) {
c.fadeOut(500)
} else {
c.fadeIn(500)
}
};
$('span').mouseenter(function() {
e = setTimeout(function() {
d()
}, b);
$(this).mouseleave(function() {
typeof e != 'undefined' && clearTimeout(e);
f = setTimeout(function() {
d(1)
}, 300)
})
});
c.mouseenter(function() {
clearTimeout(f);
typeof g != 'undefined' && clearTimeout(g)
}).mouseleave(function() {
g = setTimeout(function() {
d(1)
}, 300)
})
});
</script>
<style type="text/css" media="screen">
#box {
display: none;
width: 100px;
height: 100px;
background-color: lightblue;
}
</style>
</head>
<body>
<span>HOVER ME</span>
<div id="box"></div>
</body>
</html>
편집 : 라이브 테스트 JS 바이올린 : http://jsfiddle.net/2ogcp9tm/
문제는 코드가 잘 나는 그것을 실행되지만 처음 작동한다는 것입니다 나는의 범위를 올려 놓으면 두 번째로 파란색 상자에 마우스를 놓으려고하면 어쨌든 사라집니다.
왜 이런 일이 발생합니까?
축소 된 게시하지 마십시오 기음 ode - a, b, c ...가 아닌 의미있는 변수 이름을 사용하십시오. – Barmar
@Barmar te original var은 최악 이었기 때문에 외국어로 작성된 사용 변수보다 더 명확하기 때문에이 작업을 수행했습니다. – Flerex
좋은 점, 그것들은 꽤 성가시다. :) 그러나 때때로 우리는 그들에 대해 이해할 수있는 반면, a, b, c는 완전히 혼란 스럽습니다. – Barmar