我正在使用光滑的滑块库在右侧绘制带有图像和缩略图的滑块,我正在放置所有资源但问题仍然存在,问题是第一次加载时未显示第一张图像而右侧滑块未显示所有图片,只是最后一张,看起来很小。
这是我的代码:
<div id="previewModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">@Messages.Preview</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-xl-8">
<div class="right">
<input id="ShowAllImgs" class="hidden" type="checkbox" autocomplete="off" />
<div class="slider-container">
<div class="item-images-slider">
<div>
<img src="img.jpg"alt="img.Description" />
</div>
<div>
<img src="img.jpg"alt="img.Description" />
</div>
<div>
<img src="img.jpg"alt="img.Description" />
</div>
<div>
<img src="img.jpg"alt="img.Description" />
</div>
</div>
<div class="item-images-thumb desktop">
<div>
<img src="img.jpg"alt="img.Description" />
</div>
<div>
<img src="img.jpg"alt="img.Description" />
</div>
<div>
<img src="img.jpg"alt="img.Description" />
</div>
<div>
<img src="img.jpg"alt="img.Description" />
</div>
</div>
</div>
<div class="all-imgs">
<div>
<img src="img.jpg"alt="img.Description" />
</div>
<div>
<img src="img.jpg"alt="img.Description" />
</div>
<div>
<img src="img.jpg"alt="img.Description" />
</div>
<div>
<img src="img.jpg"alt="img.Description" />
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
和JS代码:
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/slick.js"></script>
<script>
$('.item-images-slider').slick({
infinite: true,
arrows: false,
mobileFirst: true,
speed: 300,
touchThreshold: 15,
adaptiveHeight: true,
//asNavFor: '.item-images-thumb', // for desktop
dots: true
});
$('.item-images-thumb').slick({
infinite: false,
arrows: false,
mobileFirst: true,
speed: 300,
touchThreshold: 15,
adaptiveHeight: true,
dots: false,
vertical: true,
verticalSwiping: true,
asNavFor: '.item-images-slider',
focusOnSelect: true,
slidesToShow: 2.5
});
</script>
和 CSS 代码:
<link href="~/Content/css/Slick.css" rel="stylesheet" />
<link href="~/Content/css/SlickTheme.css" rel="stylesheet" />
<style>
.right, .left {
background-color: white;
}
.slider-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
padding: 1rem;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
}
.item-images-slider {
order: 2;
}
.slider-container .slick-slider {
overflow: hidden;
}
.item-images-slider {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
border: 0.0625rem solid #e3e3e3;
overflow: hidden;
}
.slick-list {
min-width: 100%;
height: 20rem !important;
}
.slick-slider {
position: relative;
display: block;
box-sizing: border-box;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-touch-callout: none;
-khtml-user-select: none;
-ms-touch-action: pan-y;
touch-action: pan-y;
-webkit-tap-highlight-color: transparent;
}
.slick-track {
min-width: 100%;
transform: translate3d(0, 0, 0) !important;
}
.item-images-slider .slick-slide {
height: 20rem !important;
}
.slick-slide label {
margin: auto;
}
.item-images-slider .slick-slide img {
max-height: 20rem;
margin: auto;
border: 0;
background-color: transparent;
outline: 0;
max-width: 100%;
object-fit: cover;
}
.item-images-slider .slick-dots {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
position: absolute;
right: 0.5rem;
top: 1rem;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.slick-dots li {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin: 0 0.15rem 0.3rem;
}
.slick-slider .slick-active button {
background: #ff9f1a;
border: 0;
}
.slick-slider button:not(.slick-arrow) {
font-size: 0;
width: 0.8125rem;
height: 0.8125rem;
border-radius: 100%;
display: inline-block;
padding: 0 !important;
}
.item-images-thumb {
order: 1;
margin-right: 0;
margin-left: 1rem;
}
.slider-container .slick-slider {
overflow: hidden;
}
.item-images-thumb {
direction: ltr !important;
width: 9rem;
}
.slick-vertical .slick-slide {
border: 0 !important;
}
.slick-slide {
margin-top: 1rem;
}
.slick-vertical .slick-slide {
display: block;
}
.item-images-thumb .slick-slide img {
right: 50%;
position: absolute;
-webkit-transform: translate(50%, -50%);
transform: translate(50%, -50%);
top: 50%;
max-width: initial;
min-height: 100%;
max-height: 100%;
}
.slick-initialized .slick-slide {
display: block !important;
}
.all-imgs {
text-align: center;
border-bottom: 1px solid #eee;
margin-bottom: 1rem;
display: none;
}
</style>