Javascript(根据屏幕大小隐藏和显示)

Javascript (Hide and show depending on screen size)

我正在尝试创建一个响应式网站,我想在其中显示 3 个框:

(第 1 天-第 2 天-第 3 天)

我希望它在小于 436 像素的屏幕和桌面上显示的内容 See Image

我希望它负责,所以当我调整浏览器大小时,它应该跳转到小于 436 像素的屏幕,然后在桌面上调整大小。

重要提示:在桌面上时,框不应该能够隐藏内容。

我的代码:jsfiddle。net/94sfkhcu/

希望有人能提供帮助。谢谢:)

如果我没看错你需要什么。调整 window 大小时,您可以检查 window 宽度是小于还是大于 436px。然后你可以做你想做的..

   $(document).ready(function() {
      $('.bbottom2').hide();
      $('.btop').click(function(e) {
        e.preventDefault();
        var $menuItem = $(this).next('.bbottom, .bbottom2');
        $menuItem.slideToggle();
      });
      $( window ).resize(function() {
        if($(window).width()>436) $('.bbottom2').show();
        else $('.bbottom2').hide();
      });
 });

$(document).ready(function() {
        if($(window).width()<436)
      $('.bbottom2').hide();
      $('.btop').click(function(e) {
        e.preventDefault();
        var $menuItem = $(this).next('.bbottom, .bbottom2');
        $menuItem.slideToggle();
        $menuItem.toggleClass( "bbottom2" );
      });
 });
 
 
      $( window ).resize(function() {
        if($(window).width()>436) $('.bbottom, .bbottom2').show();
        else $('.bbottom2').hide();
      });
.ticket{
  margin:0;
  padding:0;
  float:left;
}

.btop2, .btop{
  background-color:grey;
  color:white;
  padding:5px 10px;
  display:block;
  width:100px;
  border-bottom:1px solid;
  pointer-events:none;
}

.btop:hover{
  background-color:darkgrey;
}

/*Responsive*/
@media screen and (max-width: 436px) {

.ticket{
  margin:0;
  padding:0;
  float:none;
}

.btop{
  background-color:red;
  pointer-events:auto;
}
  
  

.btop:hover{
  cursor:pointer;
}
  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="ticket">
    <div class="btop">Day 1</div>
    <div class="bbottom">Price 20</div>
</div>

<div class="ticket">
    <div class="btop">Day 2</div>
    <div class="bbottom bbottom2">Price 99</div>
</div>

<div class="ticket">
    <div class="btop">Day 3</div>
    <div class="bbottom bbottom2">Price 149</div>
</div>