首页 > 代码库 > 判断滚动条的滚动方向

判断滚动条的滚动方向

var beforeTop = $("#table_layout").scrollTop();
var beforeLeft = $("#table_layout").scrollTop();
$("#table_layout").scroll(function () {
var afterTop = $(this).scrollTop();
var afterLeft = $(this).scrollLeft();
if (beforeTop > afterTop) {
$("#table_layout").after("上");
beforeTop = afterTop;
}
else if (beforeTop < afterTop) {
$("#table_layout").after("下");
beforeTop = afterTop;
};
if (beforeLeft > afterLeft) {
$("#table_layout").after("左");
beforeLeft = afterLeft;
}
else if (beforeLeft < afterLeft) {
$("#table_layout").after("右");
beforeLeft = afterLeft;
}
});

判断滚动条的滚动方向