【问题标题】:Height of Owl Carousel on phone手机上猫头鹰旋转木马的高度
【发布时间】:2019-07-02 20:56:54
【问题描述】:

我有一张使用 Owl Carousel 在桌面上覆盖整个屏幕的图像。

当我在手机设备上查看同一张图片时,它只占用了屏幕大小的三分之一。

我怎样才能调整高度,使它比现在手机上的高度高?

我已经阅读了一些主题,但是对于 Owl carousel 的新手,我不确定我是否做错了什么。我找不到这门课https://css-tricks.com/forums/topic/owl-slider-100-height/ 所以不确定

我对 Owl carousel 的配置是

            items: 1,
            smartSpeed: 1000,
            autoplay: true,
            autoplayTimeout: 6000,
            dots: false,
            loop: true,
            mouseDrag: false,
            autoHeight:false,
            touchDrag: false,
            autoHeight:true

猫头鹰轮播 v2.3.4

使用的 CSS (https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css)

/**
 * Owl Carousel v2.3.4
 * Copyright 2013-2018 David Deutsch
 * Licensed under: SEE LICENSE IN https://github.com/OwlCarousel2/OwlCarousel2/blob/master/LICENSE
 */

.owl-carousel,
.owl-carousel .owl-item {
    -webkit-tap-highlight-color: transparent;
    position: relative
}

.owl-carousel {
    display: none;
    width: 100%;
    z-index: 1
}

.owl-carousel .owl-stage {
    position: relative;
    -ms-touch-action: pan-Y;
    touch-action: manipulation;
    -moz-backface-visibility: hidden
}

.owl-carousel .owl-stage:after {
    content: ".";
    display: block;
    clear: both;
    visibility: hidden;
    line-height: 0;
    height: 0
}

.owl-carousel .owl-stage-outer {
    position: relative;
    overflow: hidden;
    -webkit-transform: translate3d(0, 0, 0)
}

.owl-carousel .owl-item,
.owl-carousel .owl-wrapper {
    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    -ms-backface-visibility: hidden;
    -webkit-transform: translate3d(0, 0, 0);
    -moz-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0)
}

.owl-carousel .owl-item {
    min-height: 100%;
    float: left;
    -webkit-backface-visibility: hidden;
    -webkit-touch-callout: none
}

.owl-carousel .owl-item img {
    display: block;
    width: 100%
}

.owl-carousel .owl-dots.disabled,
.owl-carousel .owl-nav.disabled {
    display: none
}

.no-js .owl-carousel,
.owl-carousel.owl-loaded {
    display: block
}

.owl-carousel .owl-dot,
.owl-carousel .owl-nav .owl-next,
.owl-carousel .owl-nav .owl-prev {
    cursor: pointer;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none
}

.owl-carousel .owl-nav button.owl-next,
.owl-carousel .owl-nav button.owl-prev,
.owl-carousel button.owl-dot {
    background: 0 0;
    color: inherit;
    border: none;
    padding: 0!important;
    font: inherit
}

.owl-carousel.owl-loading {
    opacity: 0;
    display: block
}

.owl-carousel.owl-hidden {
    opacity: 0
}

.owl-carousel.owl-refresh .owl-item {
    visibility: hidden
}

.owl-carousel.owl-drag .owl-item {
    -ms-touch-action: pan-y;
    touch-action: pan-y;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none
}

.owl-carousel.owl-grab {
    cursor: move;
    cursor: grab
}

.owl-carousel.owl-rtl {
    direction: rtl
}

.owl-carousel.owl-rtl .owl-item {
    float: right
}

.owl-carousel .animated {
    animation-duration: 1s;
    animation-fill-mode: both
}

.owl-carousel .owl-animated-in {
    z-index: 0
}

.owl-carousel .owl-animated-out {
    z-index: 1
}

.owl-carousel .fadeOut {
    animation-name: fadeOut
}

@keyframes fadeOut {
    0% {
        opacity: 1
    }
    100% {
        opacity: 0
    }
}

.owl-height {
    transition: height .5s ease-in-out
}

.owl-carousel .owl-item .owl-lazy {
    opacity: 0;
    transition: opacity .4s ease
}

.owl-carousel .owl-item .owl-lazy:not([src]),
.owl-carousel .owl-item .owl-lazy[src^=""] {
    max-height: 0
}

.owl-carousel .owl-item img.owl-lazy {
    transform-style: preserve-3d
}

.owl-carousel .owl-video-wrapper {
    position: relative;
    height: 100%;
    background: #000
}

.owl-carousel .owl-video-play-icon {
    position: absolute;
    height: 80px;
    width: 80px;
    left: 50%;
    top: 50%;
    margin-left: -40px;
    margin-top: -40px;
    background: url(owl.video.play.png) no-repeat;
    cursor: pointer;
    z-index: 1;
    -webkit-backface-visibility: hidden;
    transition: transform .1s ease
}

.owl-carousel .owl-video-play-icon:hover {
    -ms-transform: scale(1.3, 1.3);
    transform: scale(1.3, 1.3)
}

.owl-carousel .owl-video-playing .owl-video-play-icon,
.owl-carousel .owl-video-playing .owl-video-tn {
    display: none
}

.owl-carousel .owl-video-tn {
    opacity: 0;
    height: 100%;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: contain;
    transition: opacity .4s ease
}

.owl-carousel .owl-video-frame {
    position: relative;
    z-index: 1;
    height: 100%;
    width: 100%
}

【问题讨论】:

  • 这可能需要对 CSS 进行一些调整。例如,高度:100vh;在旋转木马的容器上。并在您正在测试的各种浏览器上清楚地测试它!保存它,检查是否没有其他样式影响容器。容器的内容 - 图像 - 可能决定了容器的大小,因此考虑到容器会根据内容的纵横比进行调整,将其缩小是有意义的。
  • 本教程可能就是你要找的:webdesign.tutsplus.com/tutorials/…
  • @KurtisRogers 谢谢,我认为你是对的。我已经添加了我在上面导入的 CSS(带有我复制的演示中的链接)。我遇到了与此页面完全相同的问题owlcarousel2.github.io/OwlCarousel2/demos/basic.html - 如果您调整浏览器大小或进入开发模式并选择手机设备,您将看到颜色仅占用一部分空间 - 我希望它全高。 Michael_Eugene_Yuen 我查看了那个链接,但看起来它使用的是 Bootstrap,我没有

标签: css flexbox owl-carousel


【解决方案1】:

根据我收集到的信息,您希望容器在桌面和移动设备上使用 Owl Carousel 的全高和全宽。

我为您制作了一支笔,它可以帮助您通过 Owl Carousel 到达您想去的地方 - 我不太了解它,因为我不再使用 Carousels,但它是一个很好的选择轮播的解决方案!

https://codepen.io/kurtis-rogers/full/NozyEz

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Owl Carousel 2 Example</title>
</head>
<body>
  <div class="owl-carousel">
    <div class="post-content-parent">
      <div class="c--post-content-image-wrapper"></div>
      <div class="post-content-text-child">
        <div class="post-content--inner">
          <h2>Slider 1</h2>
          <p>Some information about slider 1</p>
        </div>
        <input type="button" value="Read more">
      </div>
    </div>
    <div class="post-content-parent">
      <div class="c--post-content-image-wrapper"></div>
      <div class="post-content-text-child">
        <div class="post-content--inner">
          <h2>Slider 1</h2>
          <p>Some information about slider 1</p>
        </div>
        <input type="button" value="Read more">
      </div>
    </div>
  </div>
</body>
</html>

CSS(SCSS):

body, html{
  padding: 0;
  margin: 0;
}

.owl-carousel, .owl-stage-outer {
  max-height: 100%;
  height: 100vh;
}

// Parent container for the images and text
.post-content-parent{
  display: flex;
  width: 100%;
  height: 100vh;
  position: relative;
}

// Post content image styles
.c--post-content-image-wrapper{
  position: absolute;
  width: 100%;
  height: 100vh;
  top: 0;
  bottom: 0;
  background: url("https://images.pexels.com/photos/132037/pexels-photo-132037.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

// Post text content
.post-content-text-child{
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.7);
  z-index: 1;
  padding: 20px 0;
  position: absolute;
  bottom: 0;
  top: auto;
  left: 0;
  right: 0;
  width: 100%;
  height: auto;
  .post-content--inner {
    padding-left: 20px;
  }
  h2 {
    font-family: Arial, sans-serif;
    font-weight: lighter;
  }
  h2, p {
    margin: 0;
  }
  input[type="button"] {
    margin-right: 20px;
  }
}

JavaScript:

$(document).ready(function(){
  $(".owl-carousel").owlCarousel({
    loop: true,
    items: 1,
    center: true,
    lazyLoad: true,
    dots: false
  });
});

如果您需要任何帮助,请告诉我 :)

【讨论】:

  • 谢谢会检查这个。感谢你的帮助。只是好奇,但我在其他网站上看到的另一种方式是它们有一个大图像,而在手机上,图像的左侧和右侧被裁剪。所以完整的图像只显示在桌面版本上。这是你做的吗?
  • 它实际上是每个 Owl 幻灯片中容器上的 CSS 背景图像。您可以在大多数 CMS'/框架的模板中完成此操作,这意味着它可以在 CSS 文件中动态而不是静态完成。背景位置与 background-size: cover; 一起负责图像定位。 - 图片没有被裁剪,它实际上只是一张背景图片 :)
  • 我添加了上面的代码(但转换为 CSS)。我看到了图像,但是如果我在桌面上查看,图像已满,但在移动设备上,它只显示图像的中心。这是有意的还是可选的?谢谢
  • 嗨计算机 - 您可能只使用一些 css 来编辑移动设备的背景位置和大小,但如果您必须为每个添加的图像更改此设置以获得图像的预期移动显示 - 相反,您应该向您的客户或经理建议将来用于轮播的每张图像都应具有相同的大小,并且每张图像看起来几乎相同,即一个人或一个产品在同一个每次放置。这更像是基于内容决策的讨论:)
【解决方案2】:

您面临的问题是因为桌面屏幕和移动屏幕的宽高比不一样。

最好的方法是为桌面设备和移动设备使用两组不同的图像。您可以为桌面显示横向图像,为移动设备显示纵向图像。

您可以尝试使用 HTML 图片元素在桌面和移动设备上显示不同的图像: https://www.w3schools.com/tags/tag_picture.asp

【讨论】:

  • 如果我使用这种方法,我认为图像不会像使用 Owl 滑块那样滑动。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-28
  • 2016-07-29
  • 1970-01-01
  • 2021-10-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多