简体   繁体   English

仅当屏幕宽度小于 600px 时,使 div 从底部消失 850px

[英]make div disappear 850px from bottom only when screen is less than 600px wide

I have this function that makes my div disappear 850 px from the bottom of the page我有这个功能可以让我的 div 从页面底部消失 850 px

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

but i'd like this to ONLY happen if the screen is 600px wide or less, how can i do this?但我希望只有在屏幕宽度为 600 像素或更小时才会发生这种情况,我该怎么做?

You can use $(window).width() :您可以使用$(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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使我的 2 个 div 在屏幕上堆叠小于 600px - Make my 2 divs stack on screen smaller than 600px <a>屏幕分辨率低于600像素时</a>无法隐藏<a>标签</a> - cant hide an <a> tag when the screen resolution is below 600px 当窗口宽度小于 600px 时,如何禁用 MUI Grid 项目堆叠 - How to disable MUI Grid items from stacking when window width is smaller than 600px 如果窗口小于 600px,则使用纯 JavaScript 有条件地加载 jquery - Load jquery conditionally with pure JavaScript if windows with < than 600px 类星体 - 垂直滚动条的宽度不超过600px - Quasar - Vertical scrollbar not working on more than 600px width 当 window 宽度等于 600px 时如何禁用 OverlayScrollbars? - How to disable OverlayScrollbars when window width equal 600px? 如何禁用滚动条是身体的宽度和高度大于1000px和600px? - How to disable the scrollbars is width and height of body bigger than 1000px and 600px? 如何使此代码仅出现在 600 像素及以上? (我不希望它出现在手机或平板电脑上) - How do I make this code only appear for 600px and upwards? (I don't want it appearing on mobile or tablet) 如何在小于600px的屏幕上“打开”页面加载的Bootstrap下拉菜单 - How to 'open' Bootstrap Dropdown menus on pageload on screens smaller than 600px 如果屏幕宽度小于 ...px,则仅执行一次操作 - Do something ONLY ONCE if screen width is less than ...px
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM