javascript - Owl Carousel 高度调节

标签 javascript jquery html carousel owl-carousel

我正在构建一个网站,其主页顶部有一个 Owl Carousel 。该网站正处于初步阶段,我在轮播方面遇到了问题。

我希望轮播保持响应,同时调整图像以填充窗口/屏幕的整个高度。换句话说,我不想调整图像大小;只是随着窗口变小而居中。现在,它们只是在窗口大小调整时缩小。

这是我当前的代码:

HTML

    <section id="sidebar">
        <div id="owl" class="owl-carousel"> 
            <div class="item" id="item-1"><img src="assets/img/motel.jpg" alt=""></div>
            <div class="item" id="item-2"><img src="assets/img/gas.jpg" alt=""></div>
            <div class="item" id="item-3"><img src="assets/img/sofia.jpg" alt=""></div>
       </div>
    </section>

JS:

    $(document).ready(function() {
        $("#owl").owlCarousel({
            navigation: true,
            slideSpeed: 300,
            paginationSpeed: 400,
            items: 1,
            autoplay: 3000,
            stopOnHover: true,
            loop: true,
        });
    });

CSS:

    #owl .item img {
        display: block;
        widows: auto;
        height: 100%;
        min-height: 523px;
    }

这里是 github 上完整站点(到目前为止)的链接:https://jnikkiyoke.github.io/project/

任何帮助将不胜感激!

最佳答案

最简单的方法是删除 <img/>标记并使用 background相反:

.item {
    height: 100vh;
    width: 100%;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
}

#item-3{
    background-image: url("assets/img/gas.jpg");
}

您还可以删除 min-height#owl .item img

您可能还想添加height: 100vh;width: auto; 。使用media queries不同的比例。

关于javascript - Owl Carousel 高度调节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43335191/

相关文章:

javascript - 为什么标签没有动画?

c# - 网络浏览器 : sequencing activites when no DocumentCompleted is fired by a link on hosted webpage

javascript - 计算父 JSON 对象内的对象数量

javascript - 无法在 Safari 中从字符串创建日期

javascript - jQuery 附加一个 CSS 并运行一个函数?

javascript - jQuery/Javascript : More complex Searching and Replacing in an HTML document

html - 跟随兄弟节点与当前 xslt/xpath

HTML 元素在一个或另一个中连续为 "nesting"

Javascript 页内滚动偏移量

javascript - JavaScript 中的单例模式