网站上的Owl-Carousel幻灯片不显示为单个项目。

huangapple go评论54阅读模式
英文:

Owl-Carousel Slideshow on Website not appear as single item

问题

我一直在尝试通过将Js设置为Items,循环或其他方式来修复此错误,还尝试编辑CSS中的容器或滑块项,但似乎都不起作用。最终,它显示出所有列表而不是逐个显示。因此,结果是,它把网站拉长了。

这是我的代码:

$(document).ready(function() {
    //for testimonial
    var owl = $('.owl-testmonial');
    owl.owlCarousel({
        items: 1,
        loop: true,
        nav: true,
        margin: 10,
        autoplay: true,
        autoplayTimeout: 2500,
        autoplayHoverPause: true
    });
});
body {
    font-family: Arial, sans-serif;
    margin: 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.testmonial {
    background-image: url(images/testimonial-bg.jpg);
    position: relative;
    background-repeat: no-repeat;
}

/* 其他CSS样式... */

.owl-carousel.owl-testmonial {
    /* 添加或修改其他样式 */
}
<!-- HTML中的结构保持不变 -->

注意:在提供的代码片段中,Js和CSS部分没有明显的错误。如果问题仍然存在,请检查其他可能影响轮播功能的部分,例如HTML结构或其他JavaScript代码。

英文:

I've been trying to fix this error by setting the Js up like the Items, the loops or else and also i try to edit the container in the CSS or even the slider-items but all seems not working out. since it's ended up showing all the list instead one by one. So, as the result, it stretched the website up.

here's my code :

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

$(document).ready(function() {

    //for testimonial
    var owl = $(&#39;.owl-testmonial&#39;);
    owl.owlCarousel({
        items: 1,
        loop: true,
        nav: true,
        margin: 10,
        autoplay: true,
        autoplayTimeout: 2500,
        autoplayHoverPause: true
    });
});

<!-- language: lang-css -->

body {
    font-family: Arial, sans-serif;
    margin: 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.testmonial {
    background-image: url(images/testimonial-bg.jpg);
    position: relative;
    background-repeat: no-repeat;
}

.testmonial:after {
    content: &quot;&quot;;
    background: #1baaba;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: .6;
    z-index: 1;
}

.owl-wrapper {
    padding: 80px 20px;
    z-index: 999;
    position: relative;
}

.owl-testmonial {
    background: #FFF;
    max-width: 400px;
    margin: 0 auto;
    padding: 40px 25px;
    position: unset;
}

.owl-testmonial:before {
    content: &quot;\f10d&quot;;
    font-family: &quot;Font Awesome 5 Free&quot;;
    font-weight: 900;
    text-align: center;
    display: block;
    font-size: 92px;
    color: #e7e7e7;
    margin-top: -106px;
}

.owl-testmonial .owl-prev {
    position: absolute;
    left: 0;
    top: 45%;
    font-size: 36px !important;
    border: 1px solid #FFF !important;
    width: 33px !important;
    height: 36px !important;
    line-height: 17px !important;
    color: #FFF;
}

.owl-testmonial .owl-next {
    position: absolute;
    right: 0;
    top: 45%;
    font-size: 36px !important;
    border: 1px solid #FFF !important;
    width: 33px !important;
    height: 36px !important;
    color: #FFF;
    line-height: 17px !important;
}

nav {
    overflow: hidden;
    background-color: #333;
}

nav.sticky {
    position: fixed;
    top: 0;
    width: 100%;
}

nav ul {
    display: flex;
    list-style: none;
    margin: 0;
}

nav li {
    margin: 0 30px;
}

nav a {
    float: left;
    display: block;
    color: #f2f2f2;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    font-size: 17px;
}

nav a:hover {
    background-color: #ffeb3b;
    color: black;
}

a.active {
    background-color: #2196f3;
    color: white;
}

.content {
    padding: 20px;
}

.sticky {
    position: fixed;
    top: 0;
    width: 100%;
}

.sticky+.content {
    padding-top: 60px;
}

.benefit-card,
.product,
.testimony,
.news-item,
.suggestion-box {
    background-color: #fff;
    width: 30%;
    height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    float: left;
}

input[type=&quot;text&quot;],
input[type=&quot;email&quot;],
input[type=&quot;tel&quot;] {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border-radius: 10px;
    border: 1px solid #ccc;
}

button[type=&quot;submit&quot;] {
    width: 100%;
    padding: 10px;
    background-color: #ffeb3b;
    color: #2196f3;
    border-radius: 10px;
    border: 1px solid #2196f3;
    margin-top: 20px;
    cursor: pointer;
}

.office-map {
    margin-top: 50px;
}


/* Responsive styles */

@media screen and (max-width: 992px) {
    nav li {
        margin: 0 10px;
    }
    .benefit-card,
    .product,
    .testimony,
    .news-item,
    .suggestion-box {
        width: 80%;
    }
}

@media screen and (max-width: 768px) {
    header {
        height: 60vh;
    }
    nav {
        top: 60vh;
    }
    .benefit-card,
    .product,
    .testimony,
    .news-item,
    .suggestion-box {
        width: 90%;
    }
}

@media screen and (max-width: 576px) {
    header {
        height: 40vh;
    }
    nav {
        top: 40vh;
    }
    .benefit-card,
    .product,
    .testimony,
    .news-item,
    .suggestion-box {
        width: 95%;
    }
}

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;!-- Add JS for owl carousel --&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;fontawesome/css/all.min.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;owlcarousel/owl.carousel.min.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;owlcarousel/owl.theme.default.min.css&quot;&gt;
&lt;script src=&quot;main.js&quot;&gt;&lt;/script&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
&lt;title&gt;My Homepage&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;testmonial&quot;&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;owl-wrapper&quot;&gt;
&lt;div class=&quot;owl-carousel owl-testmonial&quot;&gt;
&lt;div class=&quot;slide-item&quot;&gt;
&lt;img src=&quot;testimony/slider1585663811.png&quot; alt=&quot;Slide 1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;slide-item&quot;&gt;
&lt;img src=&quot;testimony/slider1589942091.png&quot; alt=&quot;Slide 2&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;slide-item&quot;&gt;
&lt;img src=&quot;testimony/slider1590030001.png&quot; alt=&quot;Slide 3&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- 7 items sticky menu bar --&gt;
&lt;nav id=&quot;navbar&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&quot;active&quot; href=&quot;#home&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#about-us&quot;&gt;About Us&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#tabungan&quot;&gt;Tabungan&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#kredit&quot;&gt;Kredit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#deposito&quot;&gt;Deposito&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#berita&quot;&gt;Berita&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#pengajuan-kredit&quot;&gt;Pengajuan Kredit&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/nav&gt;
&lt;main class=&quot;content&quot;&gt;
&lt;!-- 3 static benefits --&gt;
&lt;section class=&quot;benefits&quot;&gt;
&lt;div class=&quot;card&quot;&gt;
&lt;h3&gt;Benefit 1&lt;/h3&gt;
&lt;p&gt;Description&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;card&quot;&gt;
&lt;h3&gt;Benefit 2&lt;/h3&gt;
&lt;p&gt;Description&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;card&quot;&gt;
&lt;h3&gt;Benefit 3&lt;/h3&gt;
&lt;p&gt;Description&lt;/p&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- 3 types of product --&gt;
&lt;section class=&quot;products&quot;&gt;
&lt;h2&gt;Products&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Product 1&lt;/li&gt;
&lt;li&gt;Product 2&lt;/li&gt;
&lt;li&gt;Product 3&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;!-- ID tracking --&gt;
&lt;section class=&quot;id-tracking&quot;&gt;
&lt;h2&gt;ID Tracking&lt;/h2&gt;
&lt;p&gt;Description&lt;/p&gt;
&lt;/section&gt;
&lt;!-- 3 dynamic testimonies --&gt;
&lt;section class=&quot;testimonies&quot;&gt;
&lt;h2&gt;Testimonies&lt;/h2&gt;
&lt;div class=&quot;owl-carousel owl-theme&quot;&gt;
&lt;div class=&quot;testimony-1&quot;&gt;Testimony 1&lt;/div&gt;
&lt;div class=&quot;testimony-2&quot;&gt;Testimony 2&lt;/div&gt;
&lt;div class=&quot;testimony-3&quot;&gt;Testimony 3&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- 4 dynamic slider of news --&gt;
&lt;section class=&quot;news&quot;&gt;
&lt;h2&gt;News&lt;/h2&gt;
&lt;div class=&quot;owl-carousel owl-theme&quot;&gt;
&lt;div class=&quot;news-1&quot;&gt;News 1&lt;/div&gt;
&lt;div class=&quot;news-2&quot;&gt;News 2&lt;/div&gt;
&lt;div class=&quot;news-3&quot;&gt;News 3&lt;/div&gt;
&lt;div class=&quot;news-4&quot;&gt;News 4&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- suggestion box --&gt;
&lt;section class=&quot;suggestion-box&quot;&gt;
&lt;h2&gt;Suggestion Box&lt;/h2&gt;
&lt;form action=&quot;#&quot;&gt;
&lt;div&gt;
&lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;
&lt;input type=&quot;text&quot; id=&quot;name&quot; name=&quot;name&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;label for=&quot;phone-number&quot;&gt;Phone Number:&lt;/label&gt;
&lt;input type=&quot;text&quot; id=&quot;phone-number&quot; name=&quot;phone-number&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;
&lt;input type=&quot;email&quot; id=&quot;email&quot; name=&quot;email&quot;&gt;
&lt;/div&gt;
&lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
&lt;/form&gt;
&lt;/section&gt;
&lt;!-- static map to the office --&gt;
&lt;section class=&quot;map&quot;&gt;
&lt;h2&gt;Map to the Office&lt;/h2&gt;
&lt;img src=&quot;map.jpg&quot; alt=&quot;Map to the Office&quot;&gt;
&lt;/section&gt;
&lt;/main&gt;
&lt;script src=&quot;jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;owlcarousel/owl.carousel.min.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
window.onscroll = function() {
myFunction()
};
var navbar = document.getElementById(&quot;navbar&quot;);
var sticky = navbar.offsetTop;
function myFunction() {
if (window.pageYOffset &gt;= sticky) {
navbar.classList.add(&quot;sticky&quot;)
} else {
navbar.classList.remove(&quot;sticky&quot;);
}
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

网站上的Owl-Carousel幻灯片不显示为单个项目。

答案1

得分: 2

使用经过验证的故障排除技巧来隔离问题。保存你的代码。然后删除与走马灯无关的所有内容,看看它是否有效。它有效!(运行下面的片段)。现在逐段添加回你的代码,直到它停止工作,然后你就知道问题出在哪里。

$(document).ready(function() {

    //for testimonial
    var owl = $('.owl-testimonial');
    owl.owlCarousel({
        items: 1,
        loop: true,
        nav: true,
        margin: 10,
        autoplay: true,
        autoplayTimeout: 2500,
        autoplayHoverPause: true
    });
});
body {
    font-family: Arial, sans-serif;
    margin: 0;
}

.owl-testimonial {
    background: #FFF;
    max-width: 400px;
    margin: 0 auto;
    padding: 40px 25px;
    position: unset;
}

.owl-testimonial .owl-prev {
    position: absolute;
    left: 0;
    top: 45%;
    font-size: 36px !important;
    border: 1px solid #FFF !important;
    width: 33px !important;
    height: 36px !important;
    line-height: 17px !important;
    color: #FFF;
}

.owl-testimonial .owl-next {
    position: absolute;
    right: 0;
    top: 45%;
    font-size: 36px !important;
    border: 1px solid #FFF !important;
    width: 33px !important;
    height: 36px !important;
    color: #FFF;
    line-height: 17px !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.css">
</head>

<body>
  <div class="owl-carousel owl-testimonial">
    <div class="slide-item">
      <img src="https://shotkit.com/wp-content/uploads/2020/08/night-landscape-photography-featured.jpg" alt="Slide 1">
    </div>

    <div class="slide-item">
      <img src="https://llandscapes-10674.kxcdn.com/wp-content/uploads/2019/07/lighting.jpg" alt="Slide 2">
    </div>

    <div class="slide-item">
      <img src="https://img.freepik.com/free-vector/nature-scene-with-river-hills-forest-mountain-landscape-flat-cartoon-style-illustration_1150-37326.jpg" alt="Slide 3">
    </div>
  </div>
</body>

这些是你提供的代码的翻译部分。

英文:

Use the tried and true troubleshooting technique for isolating a problem. Save your code. Then remove everything unrelated to the carousel and see if it works. It does! (run the snippet below). Now add back your code in sections until it stops working, then you’ll know where the problem is.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

$(document).ready(function() {

    //for testimonial
    var owl = $(&#39;.owl-testmonial&#39;);
    owl.owlCarousel({
        items: 1,
        loop: true,
        nav: true,
        margin: 10,
        autoplay: true,
        autoplayTimeout: 2500,
        autoplayHoverPause: true
    });
});

<!-- language: lang-css -->

body {
font-family: Arial, sans-serif;
margin: 0;
}
.owl-testmonial {
background: #FFF;
max-width: 400px;
margin: 0 auto;
padding: 40px 25px;
position: unset;
}
.owl-testmonial .owl-prev {
position: absolute;
left: 0;
top: 45%;
font-size: 36px !important;
border: 1px solid #FFF !important;
width: 33px !important;
height: 36px !important;
line-height: 17px !important;
color: #FFF;
}
.owl-testmonial .owl-next {
position: absolute;
right: 0;
top: 45%;
font-size: 36px !important;
border: 1px solid #FFF !important;
width: 33px !important;
height: 36px !important;
color: #FFF;
line-height: 17px !important;
}

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js&quot;&gt;&lt;/script&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;owl-carousel owl-testmonial&quot;&gt;
&lt;div class=&quot;slide-item&quot;&gt;
&lt;img src=&quot;https://shotkit.com/wp-content/uploads/2020/08/night-landscape-photography-featured.jpg&quot; alt=&quot;Slide 1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;slide-item&quot;&gt;
&lt;img src=&quot;https://llandscapes-10674.kxcdn.com/wp-content/uploads/2019/07/lighting.jpg&quot; alt=&quot;Slide 2&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;slide-item&quot;&gt;
&lt;img src=&quot;https://img.freepik.com/free-vector/nature-scene-with-river-hills-forest-mountain-landscape-flat-cartoon-style-illustration_1150-37326.jpg&quot; alt=&quot;Slide 3&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月6日 08:55:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75356535.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定