javascript scroll関数
1624 ワード
//スクロール時の変化
function customScroll(obj) {
var scrObj = obj;
var perScrollTop = 0;
$(window).scroll(function() {
var scrollTop = $(window).scrollTop();
if (perScrollTop < scrollTop && perScrollTop - scrollTop <= -3 && scrObj.scrollDown !== undefined) {
//
scrObj.scrollDown();
}
if (perScrollTop > scrollTop && perScrollTop - scrollTop >= 3 && scrObj.scrollUp !== undefined) {
//
scrObj.scrollUp();
}
if (scrollTop > scrObj.data.topScrollPosition ? scrObj.data.topScrollPosition : null && scrObj.topScrollPosition !== undefined) {
//
scrObj.topScrollPosition();
}
if (scrollTop > scrObj.data.topHidePosition ? scrObj.data.topHidePosition : null && scrObj.topHidePosition !== undefined) {
//
scrObj.topHidePosition();
}
perScrollTop = scrollTop;
}).on("resize.scroll", function() {
//
scrObj.resizeScroll();
});
}
//
var scroll = new customScroll({
'data': {
'topScrollPosition': 600,
'bottomScrollPosition': 600
},
'scrollDown': function() {
console.log(' ')
},
'scrollUp': function() {
console.log(' ')
},
'topScrollPosition': function() {
console.log(' ')
},
'bottomScrollPosition': function() {
console.log(' ')
},
'resizeScroll': function() {
console.log(' ');
}
});