CSS를 조정하는 클래스를 추가하는 경우 div가 열리는 시점을보기 포트 & 외부에있는 것으로 감지하려고합니다.jQuery는 div가 뷰 포트의 외부에있는 경우 감지합니다.
그래서 기본적으로이 예제에서는 div의 절반이 누락되어 div 녹색을 켜는 클래스를 추가해야합니다. 이 코드는 div가 뷰포트 외부에 있는지 감지하기위한 것입니다.
하지만 동기화 할 수 없습니다. 나는 분명히 여기서 뭔가 잘못하고있다.
UPDATE
난 그냥 기술적 사업부의 상단과 하단 모두 바닥과 트리거 다음 뷰 포트의 상단 양쪽의 외부 간다면 무슨 일이 일어나고 있는지 작동하고 있음을 발견했습니다. 그것이 정상에서 벗어날 때만 나는 그것이 필요합니다. 여기
$(document).on("mouseenter", ":has('.infotip')", function() {
$(this).children(".infotip").addClass("active");
});
$(document).on("mouseleave", ":has('.infotip')", function() {
$(this).children(".infotip").removeClass("active");
});
// Infotip on screen
$(document).on("mouseenter", ":has('.infotip.onscreen')", function() {
var $target = $(this).children(".infotip");
if ($target.length) {
var $bounce = $target.offset().top + $target.height();
if ($bounce > $(window).height()) {
$target.addClass("test");
} else {
$target.addClass("top");
}
}
});
.infotip {
display: none;
height:500px;
width:100px;
position:absolute;
left:50px;
top:-250px;
}
.infotip.active {
display: block;
}
/* goes red when past top of viewport (which it will not do in this example) */
.infotip.top {
background-color: rgba(249, 14, 18, 1.00)
}
/* goes green if visible (which it should do when hovering) */
.infotip.test {
background-color: rgba(35, 223, 51, 1.00)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div class="team-card align">
hover me
<div class="infotip onscreen">
Iam infotip
</div>
</div>
JSFiddle
나는 정말 아무것도하지 않는 한 당신은 결코이 테스트를하지 가져 가라. 당신이 한 모든 것은 셀렉터를 바꾸는 것입니다 ..... – DCdaz@DCdaz .infotip의 높이가 녹색으로 바뀌어야하는지 확인해야하므로 선택기에서 변경했습니다. 그래서 .infotip은 내가 목표로해야 할 것입니다. – frnt
당신이 한 것은 셀렉터를 바꾸는 것입니다. – DCdaz