Toggling hide-visible overflow onclick

拈花ヽ惹草 提交于 2019-12-11 11:27:07

问题


I'm a newbie in JQuery so I ask you help to me.. How I can hide overflow in html after click on dropdown button menu and after closing toggle overflow as visible.

I tried this, but it allowed only to hide the overflow. Then how I can toggle hide-scroll?

$(document).ready(function() {
   $('.button').on('click', function() {
      $('html').css("overflow", "hidden");
   });
});

回答1:


You can do it by using .css()'s callBack function,

$(document).ready(function() {
   $('.button').on('click', function() {
      $('html').css("overflow", function(_,val){ 
           return val == "hidden" ? "scroll" : "hidden";
      });
   });
});

DEMO



来源:https://stackoverflow.com/questions/36113263/toggling-hide-visible-overflow-onclick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!