bxslider 滑动对齐中心
bxslider slide align center
我正在尝试制作视图对齐中心的滑块。中心幻灯片应该在红线的中心(div)
这是我试过的。 https://fiddle.jshell.net/4xgpgng1/1/
<style>
div.bxslider { margin:0 50%; text-align:center; }
.slide{ width: initial !important; margin: 0px 20px ; }
.slide img { width: 130px; }
</style>
<div style="position:absolute; width:140px; height:100px; border:1px solid red; margin:0 0 0 -70px; top:0;left:50%;z-index:2"></div>
<div class="bxslider">
<div class="slide a1"><img src="http://placehold.it/1000x680/112233/ffffff?text=FooBar1" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/ee5678/ffffff?text=FooBar2" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/435ab6/ffffff?text=FooBar3" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/11cc22/ffffff?text=FooBar4" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/ffa500/ffffff?text=FooBar5" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/cc44ff/ffffff?text=FooBar6" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/112233/ffffff?text=FooBar1" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/ee5678/ffffff?text=FooBar2" /></div>
</div>
<script>
$(document).ready(function(){
$('.bxslider').bxSlider({
slideWidth: 130,
minSlides: 12,
maxSlides: 12,
moveSlides: 1,
pager: false,
auto: false
});
});
</script>
请帮忙
这应该可以解决您的问题:
.slide img {
position: relative;
left: calc(50% + 20px);
}
这可能对某些人有所帮助。我通过将宽度设置为父容器
解决了类似的问题
.sliderWrapper {
max-width: 640px;
display: block;
margin: 0 auto;
}
HTML代码:
<div class="img-container">
<div class="imgGallery">
<div><img src="assets/img/Ocean.jpg" title="Funky roots"></div>
<div><img src="assets/img/Cliff.png" title="The long and winding road"></div>
<div><img src="assets/img/Tumpak-sewu.jpg" title="Happy trees"></div>
</div>
</div>
CSS代码:
.img-container div {
display: block;
margin: 0 auto;
text-align: center
}
TS代码:
$('.imgGallery').bxSlider({
mode: 'fade',
captions: false,
slideWidth: 500,
});
.bx-wrapper {
max-width: 100% !important;
}
我正在尝试制作视图对齐中心的滑块。中心幻灯片应该在红线的中心(div)
这是我试过的。 https://fiddle.jshell.net/4xgpgng1/1/
<style>
div.bxslider { margin:0 50%; text-align:center; }
.slide{ width: initial !important; margin: 0px 20px ; }
.slide img { width: 130px; }
</style>
<div style="position:absolute; width:140px; height:100px; border:1px solid red; margin:0 0 0 -70px; top:0;left:50%;z-index:2"></div>
<div class="bxslider">
<div class="slide a1"><img src="http://placehold.it/1000x680/112233/ffffff?text=FooBar1" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/ee5678/ffffff?text=FooBar2" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/435ab6/ffffff?text=FooBar3" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/11cc22/ffffff?text=FooBar4" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/ffa500/ffffff?text=FooBar5" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/cc44ff/ffffff?text=FooBar6" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/112233/ffffff?text=FooBar1" /></div>
<div class="slide"><img src="http://placehold.it/1000x680/ee5678/ffffff?text=FooBar2" /></div>
</div>
<script>
$(document).ready(function(){
$('.bxslider').bxSlider({
slideWidth: 130,
minSlides: 12,
maxSlides: 12,
moveSlides: 1,
pager: false,
auto: false
});
});
</script>
请帮忙
这应该可以解决您的问题:
.slide img {
position: relative;
left: calc(50% + 20px);
}
这可能对某些人有所帮助。我通过将宽度设置为父容器
解决了类似的问题.sliderWrapper {
max-width: 640px;
display: block;
margin: 0 auto;
}
HTML代码:
<div class="img-container">
<div class="imgGallery">
<div><img src="assets/img/Ocean.jpg" title="Funky roots"></div>
<div><img src="assets/img/Cliff.png" title="The long and winding road"></div>
<div><img src="assets/img/Tumpak-sewu.jpg" title="Happy trees"></div>
</div>
</div>
CSS代码:
.img-container div {
display: block;
margin: 0 auto;
text-align: center
}
TS代码:
$('.imgGallery').bxSlider({
mode: 'fade',
captions: false,
slideWidth: 500,
});
.bx-wrapper {
max-width: 100% !important;
}