So, here is the code
jQuery('.item').click(function() {
jQuery('.popup').show();
jQuery('.main').hide();
});
jQuery('.go_back').click(function() {
jQuery('.main').show();
jQuery('.popup').hide();
});
.box{
border-style: solid;
width: 100px;
height: 100px;
margin: 16px;
cursor: pointer;
}
.popup_content{
border-style: solid;
width: 200px;
height: 200px;
margin: 16px;
background-color: #3f51b5;
color: #fff;
padding:16px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main">
<div class="item item_1" data-id="item_1">
<div class="box container_1 ">
Item 1
</div>
</div>
<div class="item item_2" data-id="item_2">
<div class="box container_2">
Item 2
</div>
</div>
<div class="item item_3" data-id="item_3">
<div class="box container_3">
item 3
</div>
</div>
<div class="item item_4" data-id="item_4">
<div class="box container_4">
Item 4
</div>
</div>
<div class="item item_5" data-id="item_5">
<div class="box container_5">
Item 5
</div>
</div>
<div class="item item_6" data-id="item_6">
<div class="box container_6">
Item 6
</div>
</div>
<div class="item item_7" data-id="item_7">
<div class="box container_7">
Item 7
</div>
</div>
<div class="item item_8" data-id="item_8">
<div class="box container_8">
Item 8
</div>
</div>
<div class="item item_9" data-id="item_9">
<div class="box container_9">
Item 9
</div>
</div>
<div class="item item_10" data-id="item_10">
<div class="box container_10">
Item 10
</div>
</div>
</div>
<div class="popup" style="display:none;">
<div class="popup_content">
Popup content
</div>
<button type="button" class="go_back">Go back</button>
</div>
Here is the setup.
There are 10 containers in the main div. When one of them is clicked, the main div is hidden and "popup" is shown (see the js).
Now, imagine a scenario in which you click "Item 10" box which is located at the bottom of the page. Then the "popup" div will be shown. If you click "Go back" button then you will see the main content again, but now you are at the top of the page, not at "Item 10".
I know why it is scrolled to the top of page (because the popup content is shorter in height than the main div). Because the popup div will never be taller than the main div, is there a way to "Go back" to the same section of the main div?
For example, if you click "Item 10", and you see the popup content, then you click "Go back", I want to show "Item 10" instead of "Item 1" (Hope, I am making sense).