猫头鹰旋转木马2导航在边

时间:2016-11-05 20:06:46

标签: javascript html css owl-carousel

您好我正在使用猫头鹰旋转木马版本2,并且无法找到将导航放在旋转木马两侧的示例,如左右V形或箭头。你是怎么做到的?

6 个答案:

答案 0 :(得分:29)

我昨天刚刚这样做了:)

首先确保在配置

中打开导航

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

typedef Eigen::Map<const Eigen::VectorXd> MapVec;

这会将控件注入DOM,参见

https://owlcarousel2.github.io/OwlCarousel2/docs/api-classes.html

   $('#_samewidth_images').owlCarousel({
      margin:10,
      autoWidth:false,
      nav:true,
      items:4,
      navText : ['<i class="fa fa-angle-left" aria-hidden="true"></i>','<i class="fa fa-angle-right" aria-hidden="true"></i>']
  })

接下来使用CSS来定位Next和Prev控件,这就是我使用的:

<div class="owl-carousel owl-theme owl-loaded">
    <div class="owl-stage-outer">
        <div class="owl-stage">
            <div class="owl-item">...</div>
            <div class="owl-item">...</div>
            <div class="owl-item">...</div>
        </div>
    </div>
    <div class="owl-controls">
        <div class="owl-nav">
            <div class="owl-prev">prev</div>
            <div class="owl-next">next</div>
        </div>
        <div class="owl-dots">
            <div class="owl-dot active"><span></span></div>
            <div class="owl-dot"><span></span></div>
            <div class="owl-dot"><span></span></div>
        </div>
    </div>
</div>

对于我的图标,我使用了Font Awesome,但你可以使用类似的东西。请注意javascript代码中的 navText ,这是您放置自定义HTML的位置。我想你也可以使用一个图像(或者把它放在.owl-next和.owl-prev div的背景中。注意我使用了变换来使我的箭头更高。

答案 1 :(得分:3)

HTML标记

 <div id="slider" class="owl-carousel">
        <div class="item">
            <img src="assets/img/header-img.jpg" alt="" />
        </div>
        <div class="item">
            <img src="assets/img/header-img.jpg" alt="" />
        </div>
        <div class="item">
            <img src="assets/img/header-img.jpg" alt="" />
        </div>
        <div class="item">
            <img src="assets/img/header-img.jpg" alt="" />
        </div>
        <div class="item">
            <img src="assets/img/header-img.jpg" alt="" />
        </div>
    </div>

Css风格 滑块是班级名称

#slider .owl-nav div.owl-prev, 
#slider .owl-nav div.owl-next {
    color: #fff;
    font-size: 18px;
    margin-top: -20px;
    position: absolute;
    top: 50%;
    text-align: center;
    line-height: 39px;
    opacity: 0;
    border:1px solid #fff;
    width: 40px;
    height: 40px;
}
#slider .owl-nav div.owl-prev{
    left: 10%;
    -webkit-transition: 0.4s;
    -moz-transition: 0.4s;
    -o-transition: 0.4s;
    -ms-transition: 0.4s;
}
#slider .owl-nav div.owl-next {
    right: 10%;
    -webkit-transition: 0.4s;
    -moz-transition: 0.4s;
    -o-transition: 0.4s;
    -ms-transition: 0.4s;
}
#slider:hover .owl-nav div.owl-next{
    right: 2%;
    -webkit-transition: 0.4s;
    -moz-transition: 0.4s;
    -o-transition: 0.4s;
    -ms-transition: 0.4s;
    opacity: 1;
}
#slider:hover .owl-nav div.owl-prev{
    left: 2%;
    -webkit-transition: 0.4s;
    -moz-transition: 0.4s;
    -o-transition: 0.4s;
    -ms-transition: 0.4s;
    opacity: 1;
}
#slider:hover .owl-nav div.owl-next:hover,
#slider:hover .owl-nav div.owl-prev:hover{
    color:#fff;
    background: #0C94B8;
    border: 1px solid #0C94B8;
}

滑块激活

$('#slider').owlCarousel({
        loop:true,
        items: 1,
        margin:10,
        autoplay: true,
        nav:true,
        navText: ['<i class="fa fa-angle-left" aria-hidden="true"></i>', '<i class="fa fa-angle-right" aria-hidden="true"></i>']
    })

答案 2 :(得分:2)

自定义Owl Carousel 2导航箭头

来源Link

enter image description here

工作演示Link

更新 navText 属性

    $('.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: 3
            }
        }
    });

添加CSS样式

.carousel-wrap {
    width: 1000px;
    margin: auto;
    position: relative;
}
.owl-carousel .owl-nav{
    overflow: hidden;
    height: 0px;
}

.owl-theme .owl-dots .owl-dot.active span, 
.owl-theme .owl-dots .owl-dot:hover span {
    background: #2caae1;
}


.owl-carousel .item {
    text-align: center;
}
.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;
}

span.img-text {
    text-decoration: none;
    outline: none;
    transition: all 0.4s ease;
    -webkit-transition: all 0.4s ease;
    -moz-transition: all 0.4s ease;
    -o-transition: all 0.4s ease;
    cursor: pointer;
    width: 100%;
    font-size: 23px;
    display: block;
    text-transform: capitalize;
}
span.img-text:hover {
    color: #2caae1;
}

答案 3 :(得分:0)

所有滑块是班级名称

 #all-slide .owl-nav div.owl-prev, 
    #all-slide .owl-nav div.owl-next {
        color: #fff;
        font-size: 18px;
        margin-top: -20px;
        position: absolute;
        top: 50%;
        text-align: center;
        line-height: 39px;
        opacity: 0;
        border:1px solid #fff;
        width: 40px;
        height: 40px;
    }
    #all-slide .owl-nav div.owl-prev{
        left: 10%;
        -webkit-transition: 0.4s;
        -moz-transition: 0.4s;
        -o-transition: 0.4s;
        -ms-transition: 0.4s;
    }
    #all-slide .owl-nav div.owl-next {
        right: 10%;
        -webkit-transition: 0.4s;
        -moz-transition: 0.4s;
        -o-transition: 0.4s;
        -ms-transition: 0.4s;
    }
    #all-slide:hover .owl-nav div.owl-next{
        right: 2%;
        -webkit-transition: 0.4s;
        -moz-transition: 0.4s;
        -o-transition: 0.4s;
        -ms-transition: 0.4s;
        opacity: 1;
    }
    #all-slide:hover .owl-nav div.owl-prev{
        left: 2%;
        -webkit-transition: 0.4s;
        -moz-transition: 0.4s;
        -o-transition: 0.4s;
        -ms-transition: 0.4s;
        opacity: 1;
    }
    #all-slide:hover .owl-nav div.owl-next:hover,
    #all-slide:hover .owl-nav div.owl-prev:hover{
        color:#fff;
        background: #0C94B8;
        border: 1px solid #0C94B8;
    }`enter code here`

答案 4 :(得分:0)

@KevinSol上面的答案只是一点点改进。

https://stackoverflow.com/a/40449552/10933080

这是我的JS代码:

    $('.owl-carousel').owlCarousel({
      loop:true,
      margin:10,
      nav:true,
      navText : ['<i class="fa fa-angle-left" aria-hidden="true"></i>','<i class="fa fa-angle-right" aria-hidden="true"></i>'],
    });

和我的CSS代码:

    .owl-prev, .owl-next {
        width: 15px;
        height: 100px;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        display: block !important;
        border:0px solid black;
    }
    .owl-prev { left: -20px; }
    .owl-next { right: -20px; }
    .owl-prev i, .owl-next i {transform : scale(2,5); color: #ccc;}

答案 5 :(得分:0)

如果你只是想用一些 CSS 和一个箭头在一个边上,另一个在另一边没有边距,但它覆盖了滑块,你可以使用这个 CSS:

.owl-nav button span {
    font-size: 60px;
    padding: 0px 20px;
}

button.owl-prev {
    float: left;
}

button.owl-next {
    float: right;
}

.owl-nav {
    width: 100vw;
    position: absolute;
}

.owl-carousel.owl-theme.owl-loaded.owl-drag {
    display: flex;
    justify-content: center;
    align-items: center;
}