猫头鹰旋转木马,制作自定义导航

blt*_*rrr 39 html jquery css3 carousel owl-carousel

所以我有一个包含三张图像的猫头鹰旋转木马.我还在左侧和右侧添加了自定义导航箭头(.png图像).然而,这些箭头目前没用,因为我找不到实际让它们在我的猫头鹰旋转木马图像之间切换的方法.我无休止地搜索,无法找到解决方案.有任何想法吗?

Stu*_*ong 103

您需要启用导航和编辑navigationText:

>假设这是 version 1.3.2

owlgraphic.com/owlcarousel/#customizing

注意:Owl 1.3的网站现在已经关闭了,所以这里是一个分叉的Codepen示例.

$("#owl-example").owlCarousel({
  navigation: true,
  navigationText: ["<img src='myprevimage.png'>","<img src='mynextimage.png'>"]
});
Run Code Online (Sandbox Code Playgroud)

>假设它是version 2:

https://owlcarousel2.github.io/OwlCarousel2/docs/api-options.html#nav

$("#owl-example").owlCarousel({
  nav: true,
  navText: ["<img src='myprevimage.png'>","<img src='mynextimage.png'>"]
});
Run Code Online (Sandbox Code Playgroud)

个人建议:使用Slick over Owl


Ang*_* M. 10

我用css做了它,即:为箭头添加类,但你也可以使用图像.

Bellow是fontAwesome的一个例子:

JS:

owl.owlCarousel({
    ...
    // should be empty otherwise you'll still see prev and next text,
    // which is defined in js
    navText : ["",""],
    rewindNav : true,
    ...
});
Run Code Online (Sandbox Code Playgroud)

CSS

.owl-carousel .owl-nav .owl-prev,
  .owl-carousel .owl-nav .owl-next,
  .owl-carousel .owl-dot {
    font-family: 'fontAwesome';

}
.owl-carousel .owl-nav .owl-prev:before{
    // fa-chevron-left
    content: "\f053";
    margin-right:10px;
}
.owl-carousel .owl-nav .owl-next:after{
    //fa-chevron-right
    content: "\f054";
    margin-right:10px;
}
Run Code Online (Sandbox Code Playgroud)

使用图片:

.owl-carousel .owl-nav .owl-prev,
  .owl-carousel .owl-nav .owl-next,
  .owl-carousel .owl-dot {
    //width, height
    width:30px;
    height:30px;
    ...
}
.owl-carousel .owl-nav .owl-prev{
    background: url('left-icon.png') no-repeat;
}
.owl-carousel .owl-nav .owl-next{
    background: url('right-icon.png') no-repeat;
}
Run Code Online (Sandbox Code Playgroud)

也许有人会觉得这很有帮助:)


Mr.*_*ine 8

创建自定义导航并为他们提供所需的课程,然后您就可以开始了.这很简单.

我们来看一个例子:

<div class="owl-carousel">
      <div class="single_img"><img src="1.png" alt=""></div>
      <div class="single_img"><img src="2.png" alt=""></div>
      <div class="single_img"><img src="3.png" alt=""></div>
      <div class="single_img"><img src="4.png" alt=""></div>
</div>
		
<div class="slider_nav">
	<button class="am-next">Next</button>
	<button class="am-prev">Previous</button>
</div>
Run Code Online (Sandbox Code Playgroud)

在您的js文件中,您可以执行以下操作:

 $(".owl-carousel").owlCarousel({
    // you can use jQuery selector
    navText: [$('.am-next'),$('.am-prev')]
 
});
Run Code Online (Sandbox Code Playgroud)
 
Run Code Online (Sandbox Code Playgroud)


Dus*_*han 5

如果您想使用自己的自定义导航元素,

猫头鹰旋转木马1

var owl = $('.owl-carousel');
owl.owlCarousel();
// Go to the next item
$('.customNextBtn').click(function() {
    owl.trigger('owl.prev');
})
// Go to the previous item
$('.customPrevBtn').click(function() {
    owl.trigger('owl.next');
})
Run Code Online (Sandbox Code Playgroud)

猫头鹰旋转木马2

var owl = $('.owl-carousel');
owl.owlCarousel();
// Go to the next item
$('.customNextBtn').click(function() {
    owl.trigger('next.owl.carousel');
})
// Go to the previous item
$('.customPrevBtn').click(function() {
    // With optional speed parameter
    // Parameters has to be in square bracket '[]'
    owl.trigger('prev.owl.carousel', [300]);
})
Run Code Online (Sandbox Code Playgroud)