如何制作带箭头的猫头鹰走马灯,而不是上一个/下一个按钮

31

昨天我向客户展示了一个网站。我总是使用 Owl 轮播图,因为它很灵敏。然而,客户不喜欢前一个、下一个单词,并希望将它们更改为箭头。

因此,我更新了我的 script.js 文件。这很容易做到,我想分享一下。

$(document).ready(function(){
$('.owl-carousel').owlCarousel({
    nav:true,
    responsive:{
     ...
 })
 $( ".owl-prev").html('<i class="fa fa-chevron-left"></i>');
 $( ".owl-next").html('<i class="fa fa-chevron-right"></i>');
}); 

好的,就是这样。你随时可以添加更多的样式。(第一次使用您自己问题的答案,希望这是正确的地方/方式)

6个回答

63

如果你正在使用Owl Carousel 2,那么你应该使用以下内容:

$(".category-wrapper").owlCarousel({
     items : 4,
     loop  : true,
     margin : 30,
     nav    : true,
     smartSpeed :900,
     navText : ["<i class='fa fa-chevron-left'></i>","<i class='fa fa-chevron-right'></i>"]
   });

27

完整教程 在此处

演示 链接

输入图片描述

JavaScript

$('.owl-carousel').owlCarousel({
    margin: 10,
    nav: true,
    navText:["<div class='nav-btn prev-slide'></div>","<div class='nav-btn next-slide'></div>"],
    responsive: {
        0: {
            items: 1
        },
        600: {
            items: 3
        },
        1000: {
            items: 5
        }
    }
});

CSS导航栏样式

.owl-carousel .nav-btn{
  height: 47px;
  position: absolute;
  width: 26px;
  cursor: pointer;
  top: 100px !important;
}

.owl-carousel .owl-prev.disabled,
.owl-carousel .owl-next.disabled{
pointer-events: none;
opacity: 0.2;
}

.owl-carousel .prev-slide{
  background: url(nav-icon.png) no-repeat scroll 0 0;
  left: -33px;
}
.owl-carousel .next-slide{
  background: url(nav-icon.png) no-repeat scroll -24px 0px;
  right: -33px;
}
.owl-carousel .prev-slide:hover{
 background-position: 0px -53px;
}
.owl-carousel .next-slide:hover{
background-position: -24px -53px;
}   

20

对于可能正在使用Owl Carousel v 1.3.2的其他人的说明:

您可以在启用导航的设置中替换导航文本。

navigation:true,
navigationText: [
   "<i class='fa fa-chevron-left'></i>",
   "<i class='fa fa-chevron-right'></i>"
]

3
如果您正在查看 Owl Carousel 2,他们已将选项名称“navigation”更改为“nav”,将“navigationText”更改为“navText”。 - Crhistian Ramirez

17
如果您使用最新的Owl Carousel 2版本,您可以通过FontAwesome图标替换导航文本。代码如下:

$('.your-class').owlCarousel({
        loop: true,
        items: 1, // Select Item Number
        autoplay:true,
        dots: false,
        nav: true,
        navText: ["<i class='fa fa-long-arrow-left'></i>","<i class='fa fa-long-arrow-right'></i>"],

    });

16

12

这是如何在$(document).ready()函数中使用FontAwesome图标的方法:

 $( ".owl-prev").html('<i class="fa fa-chevron-left"></i>');
 $( ".owl-next").html('<i class="fa fa-chevron-right"></i>');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接