1 year ago
#76496
Shaco's Beard
SwiperJS AutoHeight doesn't seem to adjust height based on the elements inside of the container
I've been trying to learn how to use SwiperJS and one thing I have been struggling with is automatically resizing the swiper module according to the size of the screen (minus the navbar). I tried setting autoHeight to true, but when I add something inside of the swiper-wrapper, it gets stuck at a certain size. How can I fix this?
Code is here: https://jsfiddle.net/Josh0531/62p8oLqy/67/
HTML:
<link
rel="stylesheet"
href="https://unpkg.com/swiper@7/swiper-bundle.min.css"
/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<script src="https://unpkg.com/swiper@7/swiper-bundle.min.js"></script>
<script type="module">
import Swiper from 'https://unpkg.com/swiper@7/swiper-bundle.esm.browser.min.js'
const swiper = new Swiper(...)
</script>
<header>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</header>
<body class="scroll-stop">
<!-- Slider main container -->
<div class="swiper">
<!-- Additional required wrapper -->
<div class="swiper-wrapper">
<!-- Slides -->
<div class="swiper-slide">Slide 1
<img src=""/>
</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
<div class="swiper-slide">Slide 4</div>
<div class="swiper-slide">Slide 5</div>
...
</div>
<!-- If we need pagination -->
<div class="swiper-pagination"></div>
<!-- If we need navigation buttons -->
<!--- <div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>--->
<!-- If we need scrollbar -->
<div class="swiper-scrollbar"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://getbootstrap.com/docs/3.3/dist/js/bootstrap.min.js"></script>
<script src="https://getbootstrap.com/docs/3.3/assets/js/docs.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="https://getbootstrap.com/docs/3.3/assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
<footer>
This is a nice old div footer
<br> INFO INFO
<br> MORE INFO
<br> Final Row
</footer>
CSS:
header {
background-color: #083576;
color: black;
}
body::-webkit-scrollbar {
display: none;
height: 100%}
.swiper {
width: 100%;
height: auto;
}
img {
height: 10px;
}
.scroll-stop {
/*overflow: hidden;*/
}
.swiper-pagination {
left: 2px;
}
html
swiper.js
0 Answers
Your Answer