<script type="text/javascript">
function scrollFunc(e) {
userScroll=true;
if ( typeof scrollFunc.x == 'undefined' ) {
scrollFunc.x=window.pageXOffset;
scrollFunc.y=window.pageYOffset;
}
var diffX=scrollFunc.x-window.pageXOffset;
var diffY=scrollFunc.y-window.pageYOffset;
if(userScroll)
{
if( diffY<0 ) {
$(".myCar").animate({"top": "+=50px"},1000);// Scroll down
alert('down');
//$(".myCar").stop();
} else if( diffY>0 ) {
$(".myCar").animate({"top": "-=50px"},1000);
alert('Up');// Scroll up
} else {
// First scroll event
}
userScroll=false;
}
else
{
}
scrollFunc.x=window.pageXOffset;
scrollFunc.y=window.pageYOffset;
}
window.onscroll=scrollFunc
</script>
我正在尝试检测,向上和向下滚动,但是,它显示两者的警报消息,我的意思是,如果我向下或向上滚动,它显示两个警报消息。需要帮忙。!!