[英]Prevent HTML Scrolling When scrolling inside element, without hiding scrollbar
我想防止用戶在菜單內滾動時滾動正文或html。 但是,我不想設置$('html').css('overflow','hidden');
因為這樣可以使整個文檔向右移動。 我只想在菜單內滾動或滑動時禁用HTML滾動。 我嘗試了很多搜索此主題,但沒有發現對我真正有用。
菜單打開時進行設置:
var thisHeight = $(window).scrollTop();
$(window).on('scroll', function() {
$('html,body').scrollTop(thisHeight);
});
$('.noScroll').on('touchstart' , function(e) { e.preventDefault(); })
$('.noScroll').on('touchmove' , function(e) { e.preventDefault(); })
當它關閉時:
$(window).off('scroll');
$('.noScroll').off('touchstart');
$('.noScroll').off('touchmove');
$('.noScroll').on('touchstart' , function(){ return true; });
$('.noScroll').on('touchmove' , function(){ return true; });
您需要在文本div
添加class="noScroll"
,然后選中FIDDLE。
iOS解決方案基於:
如何取消綁定調用event.preventDefault()的偵聽器(使用jQuery)?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.