首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >始终在桌面上显示div并在移动屏幕上切换。

始终在桌面上显示div并在移动屏幕上切换。
EN

Stack Overflow用户
提问于 2018-02-13 15:08:07
回答 1查看 3.8K关注 0票数 5

我有两个DIVs,一个被用作按钮,仅显示在移动屏幕上,另一个包含我希望始终在桌面上可见的信息,并且可以使用Show/hide按钮在移动上切换。

在移动环境下,信息应该首先被隐藏起来。问题是当我将信息隐藏在480 it以下的屏幕上时,它在480 it上方的屏幕上是不可见的。

通过单击“显示/隐藏”按钮隐藏信息,然后在屏幕上显示您会发现的屏幕,我希望信息在这种情况下是可见的。

这是我的密码

代码语言:javascript
复制
$(document).ready(function() {
  $('.show-hide').click(function() {
    $(this).next().toggle();
  });
});
代码语言:javascript
复制
.show-hide {
  background-color: #ffa2a2;
  padding: 8px;
  display: none;
}

.information {
  background-color: #a4dca4;
  padding: 8px;
}

@media only screen and (max-width: 480px) {
  .show-hide {
    display: inline-block;
  }
  .information {
    display: none;
  }
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="show-hide">Show/Hide Info</div>

<div class="information">
  Some information here, Some information here, Some information here, Some information here, Some information here, Some information here, Some information here,
</div>

EN

回答 1

Stack Overflow用户

发布于 2018-02-13 15:52:28

代码语言:javascript
复制
$(document).ready(function() {
      $('.show-hide').click(function() {
        $(this).next().toggle();
      });
   
  

  $( window ).resize(function() {
    if( $( window ).width()>480){
      $('.information').toggle(true);
    }else{
      $('.information').toggle(false);
    }
    });
    });
代码语言:javascript
复制
.show-hide {
      background-color: #ffa2a2;
      padding: 8px;
      display: none;
    }

    .information {
      background-color: #a4dca4;
      padding: 8px;
    }

    @media only screen and (max-width: 480px) {
      .show-hide {
        display: inline-block;
      }
      .information {
        display: none;
      }
    }
    @media only screen and (min-width: 480px) {
      .show-hide {
        display: none;
      }
      .information {
        display: block;
      }
    }
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="show-hide">Show/Hide Info</div>

    <div class="information">
      Some information here, Some information here, Some information here, Some information here, Some information here, Some information here, Some information here,
    </div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48769855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档