[英]how can I enable and disable scroll by clicking the same element with jquery?
我想在單擊頁面的“菜單圖標”時禁用滾動,然后在再次單擊菜單關閉時再次啟用滾動。
我正在嘗試這樣的事情:
$(document).ready(function(){
$(".menu").click(function (e) {
$(".menucontent").show();
if ( $(".menucontent").is(":visible")) {
$('html, body').css({ overflow: 'hidden', height: '100%'});
}else{
$('html, body').css({ overflow: 'auto', height: 'auto'});
}
});
});
但我需要一些幫助,因為我是這種語言的新手
你應該把toggle()
代替show
toggle :顯示或隱藏匹配的元素。
$(document).ready(function(){
$(".menu").click(function (e) {
$(".menucontent").toggle();
if ( $(".menucontent").is(":visible")) {
$('html, body').css({ overflow: 'hidden', height: '100%'});
}else{
$('html, body').css({ overflow: 'auto', height: 'auto'});
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.