Bel Bel - 21 days ago 6
Javascript Question

Javascript (Hide and show depending on screen size)

Im trying to create a responsive website, where I wanna show 3 boxes:

(Day 1 - Day 2 - Day 3)

What I want it to look in screen smaller then 436px and desktop
See Image

I want it to be responsible, so when I resize my browser, it should jump to screen smaller then 436px and resize back when its on desktop.

Important: When on desktop, the boxes shouldnt be able to hide the content.

MY CODE: jsfiddle.net/94sfkhcu/

Hope somebody can help. Thank you :)

BLS BLS
Answer

$(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>

Comments