单击按钮,html的溢出y变为隐藏,如果再次单击,则返回可见

时间:2016-02-14 12:57:45

标签: javascript click

我正在尝试做这件事:我希望这一点,当点击一个按钮时,我的html的溢出会被隐藏起来。然后,再次单击时,它会变为可见,依此类推。到目前为止,我已经这样做了:(按钮有id #plus)

$('#plus').click(function () {
   $("html").css({
      'overflow-y': 'hidden',
   });
});

当然只有一次工作。我该怎么回头?

1 个答案:

答案 0 :(得分:1)

$('#plus').click(function () {
   var overflowY = 'hidden'; 
   if($("html").css('overflow-y') == 'hidden') overflowY = 'visible';
   $("html").css({ 'overflow-y': overflowY });
});
html, body {
  height:200%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="plus">Change Overflow Y</button>