javascript - Swipe carousel responsiveness -
i'm using swipe carousel, need make responsive (decrease image height , width while resizing browser), not sure why, .swiper-slide
width remaining larger, though it's width auto. did meet such problem? after browser maximize, image widths not updated. see in screenshots.
html
<div class="block-carousel"> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"> <?= html::image('/assets/images/tmp/carousel/img1.jpg') ?> </div> <div class="swiper-slide"> <?= html::image('/assets/images/tmp/carousel/img2.jpg') ?> </div> <div class="swiper-slide"> <?= html::image('/assets/images/tmp/carousel/img1.jpg') ?> </div> <div class="swiper-slide"> <?= html::image('/assets/images/tmp/carousel/img1.jpg') ?> </div> <div class="swiper-slide"> <?= html::image('/assets/images/tmp/carousel/img1.jpg') ?> </div> <div class="swiper-slide"> <?= html::image('/assets/images/tmp/carousel/img1.jpg') ?> </div> <div class="swiper-slide"> <?= html::image('/assets/images/tmp/carousel/img2.jpg') ?> </div> <div class="swiper-slide"> <?= html::image('/assets/images/tmp/carousel/img1.jpg') ?> </div> </div> <div class="swiper-pagination"> <div class="swiper-prev"> <i class="fa fa-angle-left"></i> </div> <div class="swiper-next"> <i class="fa fa-angle-right"></i> </div> </div> </div> </div>
js
$(document).ready(function(){ var swiper = new swiper('.swiper-container', { slidesperview: 'auto', nextbutton: '.swiper-next', prevbutton: '.swiper-prev', paginationclickable: true }); var imgheight = $(window).width()/2; $('.swiper-slide').each(function(){ var width = $(this).children('img').width(); $(this).css('width', width + 'px'); }); $('.block-carousel').css('height', imgheight + 'px'); }); $(window).resize(function() { var imgheight = $(window).width()/2; $('.swiper-slide').each(function(){ var width = $(this).children('img').width(); $(this).css('width', width + 'px'); }); $('.block-carousel').css('height', imgheight + 'px'); });
css
.swiper-container .swiper-slide { max-width: 700px; margin-left: 3px; margin-right: 0!important; display: inline-block; width: auto; overflow: hidden; } .swiper-container .swiper-slide img { width: auto; } .swiper-container .swiper-slide:first-child { margin-left: 0; } .swiper-wrapper * { height: 100%; } .swiper-container { height: 100%; } .swiper-container-horizontal > .swiper-pagination { bottom: auto; top: 50%; margin-top: -60px; } .swiper-prev, .swiper-next { width: 60px; height: 120px; background: rgba(0, 0, 0, 0.2); line-height: 150px; cursor: pointer; border-radius: 3px; -webkit-transition: 0.2s; -moz-transition: 0.2s; -o-transition: 0.2s; transition: 0.2s; } .swiper-prev { margin-left: 45px; float: left; } .swiper-next { margin-right: 45px; float: right; }
code in fiddle, reasons it's not working.
note: want make carousel responsive (resize images height/width during browser resize)
Comments
Post a Comment