0

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 :)

5
  • @mathiasfk how would you do it?
    – Bel
    Commented Nov 11, 2016 at 12:33
  • @mathiasfk If I hide it with the css, how do I make it show again, when clicking on it?
    – Bel
    Commented Nov 11, 2016 at 12:37
  • Ok, so I guess what you are asking is a different thing that I first thought. The menu is already responsive. You just want to assure the content cannot be hidden when in the desktop layout.
    – mathiasfk
    Commented Nov 11, 2016 at 12:44
  • @mathiasfk yes thats what i want :) See the Image
    – Bel
    Commented Nov 11, 2016 at 12:51
  • Here is a solution that works - Link
    – BLS
    Commented Nov 13, 2016 at 16:12

2 Answers 2

2

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

0

If I understand correctly what you need. When the window is resized, you can check if a window width is lesser or greater than 436px. Then you can do, what you want..

   $(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();
      });
 });
2
  • Yes thats what I want. But Im missing two more thing. 1. When on desktop, I want the content to be showen all the time. When I refresh the page on a desktop, its not showing. But when I start resizing the browser it shows again. Try it on jfiddle. 2. When on desktop, I want the the class "btop" not to be clickable. Right now its expanding the bbottom, when im on the desktop.
    – Bel
    Commented Nov 11, 2016 at 22:50
  • Hello Again I've updated the script. Now It works how I want it. Im just missing one last thing The class "btop" is still clickable on the desktop. I want it not to be clickable. How to do? Here is my code: jsfiddle.net/94sfkhcu/3
    – Bel
    Commented Nov 12, 2016 at 0:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.