87,904
社区成员
发帖
与我相关
我的任务
分享
$(document).ready(function(){
$(document).mousemove(function(e){
$("#testspan").text(e.pageX + ", " + e.pageY);
});
});
$(document).mousemove(function(e){
$("#testspan").text(e.pageX + ", " + e.pageY + ":" + e.screenY);
if((e.pageY <= 0) || (e.screenY <= 0))
{
$(".pg_header").css("top", "2px");
$(".top-left").css("top", "72px");
$(".top-right").css("top", "72px");
}
else if(e.pageY > $(".pg_hd_size").height())
{
$(".pg_header").css("top", "-300px");
$(".top-left").css("top", "6px");
$(".top-right").css("top", "6px");
}
});
[/quote]
这样不行。你用mousemove事件是不行的。
mousemove事件是无法获取event.pageY小于0的,或者说当event.pageY小于0的时候,mousemove事件不可能被触发。
要用mouseleave或mouseout事件才行
[/quote]
搞定了,用的mouseleave方法,可以说是取巧吧,判断鼠标离开页面时距离上边缘最近的话,显示导航栏,鼠标在页面内移动时如果距离页面顶端的距离大于导航栏的高度,则隐藏导航栏,代码如下:
//This is for navigation bar hide.
$(document).mouseleave(function(e){
$("#testspan").text(e.pageX + ", " + e.pageY + ", " + $(window).height() + ", " + $(window).width());
if(e.pageX <= $(window).height())
{
if(e.pageY < e.pageX)
{
$(".pg_header").css("top", "2px");
$(".top-left").css("top", "72px");
$(".top-right").css("top", "72px");
}
}
else{
if(e.pageY < ($(window).width() -e.pageX)){
$(".pg_header").css("top", "2px");
$(".top-left").css("top", "72px");
$(".top-right").css("top", "72px");
}
}
});
//This is for navigation bar show.
$(document).mousemove(function(e){
if(e.pageY > $(".pg_hd_size").height())
{
$(".pg_header").css("top", "-300px");
$(".top-left").css("top", "6px");
$(".top-right").css("top", "6px");
}
});
$(document).mousemove(function(e){
$("#testspan").text(e.pageX + ", " + e.pageY + ":" + e.screenY);
if((e.pageY <= 0) || (e.screenY <= 0))
{
$(".pg_header").css("top", "2px");
$(".top-left").css("top", "72px");
$(".top-right").css("top", "72px");
}
else if(e.pageY > $(".pg_hd_size").height())
{
$(".pg_header").css("top", "-300px");
$(".top-left").css("top", "6px");
$(".top-right").css("top", "6px");
}
});
$(document).mousemove(function(e){
$("#testspan").text(e.pageX + ", " + e.pageY + ":" + e.screenY);
if((e.pageY <= 0) || (e.screenY <= 0))
{
$(".pg_header").css("top", "2px");
$(".top-left").css("top", "72px");
$(".top-right").css("top", "72px");
}
else if(e.pageY > $(".pg_hd_size").height())
{
$(".pg_header").css("top", "-300px");
$(".top-left").css("top", "6px");
$(".top-right").css("top", "6px");
}
});
[/quote]
这样不行。你用mousemove事件是不行的。
mousemove事件是无法获取event.pageY小于0的,或者说当event.pageY小于0的时候,mousemove事件不可能被触发。
要用mouseleave或mouseout事件才行
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="testspan"></div>
<script type="text/javascript">
$(document).mouseleave(function(e){
$("#testspan").text(e.pageX + ", " + e.pageY);
if (e.pageY<=0)
alert("鼠标从上方移出");
})
</script>