먼저 스크롤이 중단 된 시간을 확인하는 기능을 사용했습니다. 그런 다음 다른 기능을 사용하여 센터로 다시 이동했습니다.
(function(){
var special = jQuery.event.special,
uid1 = 'D' + (+new Date()),
uid2 = 'D' + (+new Date() + 1);
special.scrollstart = {
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
} else {
evt.type = 'scrollstart';
jQuery.event.handle.apply(_self, _args);
}
timer = setTimeout(function(){
timer = null;
}, special.scrollstop.latency);
};
jQuery(this).bind('scroll', handler).data(uid1, handler);
},
teardown: function(){
jQuery(this).unbind('scroll', jQuery(this).data(uid1));
}
};
special.scrollstop = {
latency: 300,
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(function(){
timer = null;
evt.type = 'scrollstop';
jQuery.event.handle.apply(_self, _args);
}, special.scrollstop.latency);
};
jQuery(this).bind('scroll', handler).data(uid2, handler);
},
teardown: function() {
jQuery(this).unbind('scroll', jQuery(this).data(uid2));
}
};
})();
jQuery(window).bind('scrollstop', function(e){
// block horizontal scrolling
window.scrollTo(0,jQuery(window).scrollTop());
});
가로 스크롤링 만 사용 중지하려면이 기능을 사용할 수 있습니까? 수직 스크롤을 허용하고 싶습니다. – codelove
이것은 작동하지 않습니다. 화면을 제자리에 고정시키고 모든 스크롤을 방지합니다. 또한, 당신이 그것을 변경하더라도 : window.scrollTo (0, jQuery (window) .scrollTop()); 수직으로 스크롤하는 것이 심하게 방해됩니다. 아래 내 솔루션을 사용해보십시오. – deweydb