我想要做的是在窗口底部有一個小的導航菜單,只有當光標位置靠近底部時才顯示。我能夠讓它顯示,但不能再隱藏。我嘗試過mouseleave
,mouseout
和if
,但無法完成它的工作。下面是我,直到我被卡住:jQuery - 通過光標位置隱藏/顯示頁腳導航
\t $(document).mousemove(function(e) {
\t var cursorPosition = e.pageY - $(window).scrollTop();
\t var windowHeight = $(window).height() - 60;
\t if (cursorPosition >= windowHeight) {
\t $('#thumbnail-nav').animate({
\t bottom: '-20px'
\t }, 500);
\t }
\t });
#thumbnail-nav {
position: fixed;
height: 110px;
bottom: -150px;
padding: 10px 15px;
width: 50%;
left: calc(50% - 25%);
background: rgba(0, 0, 0, .8);
border-radius: 5px 5px 0 0;
display: -webkit-flex;
display: flex;
}
#thumbnail-nav li {
display: inline-block;
text-align: center;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
}
<ul id="thumbnail-nav">
<li>
<a href="">
<img src="http://placehold.it/100x100" alt="" />
</a>
</li>
<li>
<a href="">
<img src="http://placehold.it/100x100" alt="" />
</a>
</li>
<li>
<a href="">
<img src="http://placehold.it/100x100" alt="" />
</a>
</li>
</ul>
這裏是一個fiddle。
有人能給我這個小方向嗎?
你需要做一些事情時,光標位置比窗口的高度。 – abaracedo 2015-02-23 18:09:05