首页 > 解决方案 > 仅当屏幕宽度小于 600px 时,使 div 从底部消失 850px

问题描述

我有这个功能可以让我的 div 从页面底部消失 850 px

<script type="text/javascript">
  
  $(window).scroll(function() {
  if($(window).scrollTop() + $(window).height() > $(document).height() - 850) {
    $('.guide').hide();
  }
  else {
    $('.guide').show();
  }
});
</script>

但我希望这仅在屏幕宽度为 600 像素或更小的情况下才会发生,我该怎么做?

标签: javascripthtmljquerycss

解决方案


您可以使用$(window).width()

<script type="text/javascript">
  
  $(window).scroll(function() {
  if($(window).scrollTop() + $(window).height() > $(document).height() - 850 && $(window).width() <= 600) {
    $('.guide').hide();
  }
  else {
    $('.guide').show();
  }
});
</script>

推荐阅读