divを開いたときに、ビューポートの外側にあるのを検出しようとしています& cssを調整するクラスが追加されています。jQueryは、divがビューのポートから垂直に外れているかどうかを検出します。
基本的にこの例ではdivの半分が欠落していますのでdivの緑色になるクラスを追加する必要があります。このコードはdivがビューポートの外側にあることを検出するためのものです。
しかし、私はそれを同期することはできません。私は明らかにここで何か間違っています。
UPDATE
私はdiv要素の上部と下部の両方が、ビューポートの下部と上部の両方の外に出た場合、それが引き金技術的に何が起こっているか動作していることに気づきました。私はそれが上から外に出たときだけトリガーする必要があります。ここで
$(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>
私はそれが本当に何もしないとあなたはこれをテストしたことがないそれを取ります。 – DCdaz
@DCdaz .infotipの高さが緑色に変わったときにチェックする必要があるので、セレクタで変更を加えました。 .infotipは私が目標とする必要があるものです。 – frnt
あなたがしたのは、セレクタを変更することだけです。それ以外は何もしません。 – DCdaz