gpt4 book ai didi

javascript - 高度不是100%

转载 作者:行者123 更新时间:2023-11-28 15:15:11 24 4
gpt4 key购买 nike

我正在使用 Swiper 创建带有缩略图的垂直幻灯片。缩略图效果很好,但是即使我没有指定高度, slider 的高度也很奇怪。我试过设置为 100%,但这不起作用。想法?

参见 CodePen:https://codepen.io/anon/pen/bYLxvo

var galleryTop = new Swiper('.gallery-top', {
autoHeight: true,
direction: 'vertical',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
spaceBetween: 10,
onSlideChangeEnd: function(swiper) {
var activeIndex = swiper.activeIndex;
$(galleryThumbs.slides).removeClass('is-selected');
$(galleryThumbs.slides).eq(activeIndex).addClass('is-selected');
galleryThumbs.slideTo(activeIndex, 255, false);
}
});

var galleryThumbs = new Swiper('.gallery-thumbs', {
spaceBetween: 10,
freeMode: true,
centeredSlides: false,
slidesPerView: 'auto',
direction: 'vertical',
touchRatio: 0.2,
onClick: function(swiper, event) {
var clicked = swiper.clickedIndex
swiper.activeIndex = clicked; //don't need this
swiper.updateClasses() //don't need this
$(swiper.slides).removeClass('is-selected');
$(swiper.clickedSlide).addClass('is-selected');
galleryTop.slideTo(clicked, 255, false);
}
});
html,
body {
position: relative;
}

.group:after {
content: "";
display: table;
clear: both;
}

swiper {
width: 600px;
display: block !important;
background: red !important;
}

.swiper-container {
width: 100%;
}

.swiper-slide img {
width: 100%;
}

.gallery-top .swiper-slide {
display: inline-block;
}

.gallery-top {
width: calc(100% - 120px);
float: right;
background: blue;
}

.gallery-thumbs {
position: relative;
height: 100% !important;
width: 120px;
float: left;
display: table-cell;
text-align: center;
vertical-align: middle;
background: green;
}

.gallery-thumbs .swiper-slide {
width: 75px;
height: 75px;
border: 1px solid #fff;
background-size: cover !important;
display: inline-block;
vertical-align: middle;
}

.gallery-thumbs .swiper-slide-active {
border: 1px solid #ddd;
}

.gallery-thumbs .swiper-slide.is-selected {
opacity: 1;
border: 1px solid #ddd;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.2.6/js/swiper.min.js"></script>
<swiper class="group">
<!-- Swiper -->
<div class="swiper-container gallery-top">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="https://cdn.shopify.com/s/files/1/0978/6390/products/balancing-treatment.jpg?v=1508592020" />
</div>
<div class="swiper-slide">
<img src="https://cdn.shopify.com/s/files/1/0978/6390/products/balancing.jpg?v=1508592020" />
</div>
<div class="swiper-slide">
<img src="https://cdn.shopify.com/s/files/1/0978/6390/products/balancing-treatment-box.jpg?v=1508594651" />
</div>

</div>
<!-- Add Arrows -->
<div class="swiper-button-next swiper-button-white"></div>
<div class="swiper-button-prev swiper-button-white"></div>
</div>
<div class="swiper-container gallery-thumbs">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="https://cdn.shopify.com/s/files/1/0978/6390/products/balancing-treatment.jpg?v=1508592020" />
</div>
<div class="swiper-slide">
<img src="https://cdn.shopify.com/s/files/1/0978/6390/products/balancing.jpg?v=1508592020" />
</div>
<div class="swiper-slide">
<img src="https://cdn.shopify.com/s/files/1/0978/6390/products/balancing-treatment-box.jpg?v=1508594651" />
</div>
</div>
</swiper>

最佳答案

啊,好老的 100% 高度问题...

尝试将 100% 高度属性添加到您的 HTMLBODY

html,
body {
position: relative;
height: 100%;
}

我一直面临的最大挑战就是围绕这个问题,但请想想引导您的 slider 的 DOM 树结构,并确保它们都展开到 100%。

看看你是怎么处理的。

关于javascript - 高度不是100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47402030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com