区域滚动到顶部底部阻止滚动 - davy-gan/web GitHub Wiki
$.fn.scrollUnique = function () {
return $(this).each(function () {
var eventType = 'mousewheel';
// 火狐是DOMMouseScroll事件
if (document.mozHidden !== undefined) {
eventType = 'DOMMouseScroll';
}
$(this).on(eventType, function (event) {
// 一些数据
var scrollTop = this.scrollTop,
scrollHeight = this.scrollHeight,
height = this.clientHeight;
var delta = (event.originalEvent.wheelDelta) ? event.originalEvent.wheelDelta : -(event.originalEvent.detail || 0);
if ((delta > 0 && scrollTop <= delta) || (delta < 0 && scrollHeight - height - scrollTop <= -1 * delta)) {
// IE浏览器下滚动会跨越边界直接影响父级滚动,因此,临界时候手动边界滚动定位
this.scrollTop = delta > 0 ? 0 : scrollHeight;
// 向上滚 || 向下滚
event.preventDefault();
}
});
});
};
$('.chat-content').scrollUnique();
watch: {
FormVisible() {
let mo = function(e) {
e.preventDefault()
}
if (!this.FormVisible) {
document.body.style.overflow = ''
document.removeEventListener('touchmove', mo, false)
}
if (this.FormVisible) {
document.body.style.overflow = 'hidden'
document.addEventListener('touchmove', mo, false)
}
}
}
————————————————
版权声明:本文为CSDN博主「star星辉」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_43227958/java/article/details/90484887