When I scroll through the content of menu1
and then click on the menu2
tab, the content for the menu2
tab is displayed. However, I am facing an issue with changing the scroll position of the tab content so that it is visible from the top.
I attempted to use javascript, but encountered a specific problem.
.nav-tabs{
background:#f1f1f1;
position: sticky;
top: 56px;
z-index:9999;
}
body{
width:400px;
height:300px;
overflow:scroll;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<body>
<div class="container">
<h2>Dynamic Tabs</h2>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#menu1">Menu 1</a></li>
<li><a data-toggle="tab" href="#menu2">Menu 2</a></li>
</ul>
<div class="tab-content">
<div id="menu1" class="tab-pane fade in active">
<h3>Menu 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Curabitur fringilla ex ut lorem molestie, quis hendrerit neque consequat.
Donec et enim vitae purus condimentum pretium ac vel ante.
Quisque posuere arcu nec mi aliquam tincidunt.
Nullam blandit ultricies est ac vulputate.
Nam non risus non nunc fermentum bibendum eget vel sem.Sed semper magna urna.
Fusce iaculis justo metus, a viverra tortor facilisis at.
Nullam ornare volutpat nisl, sed cursus libero dapibus eu.
Integer mollis metus sed justo consectetur, non laoreet odio convallis.
Sed lobortis velit lacus, vel bibendum dui eleifend sit amet.
Morbi pulvinar nunc lacus, sollicitudin accumsan sapien imperdiet eu.
Aenean luctus nisi a orci tempus suscipit.Quisque pharetra sagittis mattis.Suspendisse potenti.
Etiam dignissim efficitur ligula, at dictum orci vestibulum rhoncus.
Proin faucibus felis massa, eu malesuada erat commodo ac.
Cras congue tellus augue, a vehicula turpis tristique in.Duis sodales mauris diam!
Ut pellentesque eros non maximus elementum.Mauris finibus porttitor rutrum?
</p>
</div>
<div id="menu2" class="tab-pane fade">
<h3>Menu 2</h3>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
</p>
</div>
</div>
</div>
</body>