2015-04-26 399 views
32

我想更改我的滑動滑塊中的箭頭但它不會更改。我想要下一個和上一個按鈕作爲圖像。我曾嘗試將它放在<style>中,但它仍不起作用。我可以在哪裏更改箭頭設置?更改滑動滑塊中的箭頭按鈕

slick theme css @charset「UTF-8」;

// Default Variables 

$slick-font-path: "./fonts/" !default; 
$slick-font-family: "slick" !default; 
$slick-loader-path: "./" !default; 
$slick-arrow-color: white !default; 
$slick-dot-color: black !default; 
$slick-dot-color-active: $slick-dot-color !default; 
$slick-prev-character: "←" !default; 
$slick-next-character: "→" !default; 
$slick-dot-character: "•" !default; 
$slick-dot-size: 6px !default; 
$slick-opacity-default: 0.75 !default; 
$slick-opacity-on-hover: 1 !default; 
$slick-opacity-not-active: 0.25 !default; 

@function slick-image-url($url) { 
    @if function-exists(image-url) { 
     @return image-url($url); 
    } 
    @else { 
     @return url($slick-loader-path + $url); 
    } 
} 

@function slick-font-url($url) { 
    @if function-exists(font-url) { 
     @return font-url($url); 
    } 
    @else { 
     @return url($slick-font-path + $url); 
    } 
} 

/* Slider */ 

.slick-list { 
    .slick-loading & { 
     background: #fff slick-image-url("ajax-loader.gif") center center no-repeat; 
    } 
    position: absolute; 
    margin: 0 auto; 
} 

/* Icons */ 
@if $slick-font-family == "slick" { 
    @font-face { 
     font-family: "slick"; 
     src: slick-font-url("slick.eot"); 
     src: slick-font-url("slick.eot?#iefix") format("embedded-opentype"), slick-font-url("slick.woff") format("woff"), slick-font-url("slick.ttf") format("truetype"), slick-font-url("slick.svg#slick") format("svg"); 
     font-weight: normal; 
     font-style: normal; 
    } 
} 

/* Arrows */ 

.slick-prev, 
.slick-next { 
    position: absolute; 
    display: block; 
    height: 20px; 
    width: 30px; 
    line-height: 0px; 
    font-size: 0px; 
    cursor: pointer; 
    background: transparent; 
    color: transparent; 
    top: 50%; 
    margin-top: -10px; 
    padding: 0; 
    border: none; 
    outline: none; 
    &:hover, &:focus { 
     outline: none; 
     background: transparent; 
     color: transparent; 
     &:before { 
      opacity: $slick-opacity-on-hover; 
     } 
    } 
    &.slick-disabled:before { 
     opacity: $slick-opacity-not-active; 
    } 
} 

.slick-prev:before, .slick-next:before { 
    font-family: $slick-font-family; 
    font-size: 20px; 
    line-height: 1; 
    color: $slick-arrow-color; 
    opacity: $slick-opacity-default; 
    -webkit-font-smoothing: antialiased; 
    -moz-osx-font-smoothing: grayscale; 
} 

.slick-prev { 
    left: -25px; 
    [dir="rtl"] & { 
     left: auto; 
     right: -25px; 
    } 
    &:before { 
     content: $slick-prev-character; 
     [dir="rtl"] & { 
      content: $slick-next-character; 
     } 
    } 
} 

.slick-next { 
    right: -25px; 
    [dir="rtl"] & { 
     left: -25px; 
     right: auto; 
    } 
    &:before { 
     content: $slick-next-character; 
     [dir="rtl"] & { 
      content: $slick-prev-character; 
     } 
    } 
} 

/* Dots */ 

.slick-slider { 
    margin-bottom: 30px; 
} 

.slick-dots { 
    position: absolute; 
    bottom: -45px; 
    list-style: none; 
    display: block; 
    text-align: center; 
    padding: 0; 
    width: 100%; 
    li { 
     position: relative; 
     display: inline-block; 
     height: 20px; 
     width: 20px; 
     margin: 0 5px; 
     padding: 0; 
     cursor: pointer; 
     button { 
      border: 0; 
      background: transparent; 
      display: block; 
      height: 20px; 
      width: 20px; 
      outline: none; 
      line-height: 0px; 
      font-size: 0px; 
      color: transparent; 
      padding: 5px; 
      cursor: pointer; 
      &:hover, &:focus { 
       outline: none; 
       &:before { 
        opacity: $slick-opacity-on-hover; 
       } 
      } 
      &:before { 
       position: absolute; 
       top: 0; 
       left: 0; 
       content: $slick-dot-character; 
       width: 20px; 
       height: 20px; 
       font-family: $slick-font-family; 
       font-size: $slick-dot-size; 
       line-height: 20px; 
       text-align: center; 
       color: $slick-dot-color; 
       opacity: $slick-opacity-not-active; 
       -webkit-font-smoothing: antialiased; 
       -moz-osx-font-smoothing: grayscale; 
      } 
     } 
     &.slick-active button:before { 
      color: $slick-dot-color-active; 
      opacity: $slick-opacity-default; 
     } 
    } 
} 

光滑CSS

/* Slider */ 

.slick-slider { 
    position: relative; 
    margin: 0 auto; 
    display: block; 
    box-sizing: border-box; 
    -moz-box-sizing: border-box; 
    -webkit-touch-callout: none; 
    -webkit-user-select: none; 
    -khtml-user-select: none; 
    -moz-user-select: none; 
    -ms-user-select: none; 
    user-select: none; 
    -ms-touch-action: pan-y; 
    touch-action: pan-y; 
    -webkit-tap-highlight-color: transparent; 
} 
.slick-list { 
    position: relative; 
    overflow: hidden; 
    display: block; 
    margin: 0 auto; 
    padding: 0; 

    &:focus { 
     outline: none; 
    } 

    &.dragging { 
     cursor: pointer; 
     cursor: hand; 
    } 
} 
.slick-slider .slick-track, 
.slick-slider .slick-list { 
    -webkit-transform: translate3d(0, 0, 0); 
    -moz-transform: translate3d(0, 0, 0); 
    -ms-transform: translate3d(0, 0, 0); 
    -o-transform: translate3d(0, 0, 0); 
    transform: translate3d(0, 0, 0); 
} 

.slick-track { 
    position: relative; 
    left: 0; 
    top: 0; 
    display: block; 

    &:before, 
    &:after { 
     content: ""; 
     display: table; 
    } 

    &:after { 
     clear: both; 
    } 

    .slick-loading & { 
     visibility: hidden; 
    } 
} 
.slick-slide { 
    float: left; 
    min-height: 1px; 
    [dir="rtl"] & { 
     float: right; 
    } 
    img { 
     display: block; 
    } 
    &.slick-loading img { 
     display: none; 
    } 

    display: none; 

    &.dragging img { 
     pointer-events: none; 
    } 

    .slick-initialized & { 
     display: block; 
    } 

    .slick-loading & { 
     visibility: hidden; 
    } 

    .slick-vertical & { 
     display: block; 
     height: auto; 
     border: 1px solid transparent; 
    } 
} 

preview of the site

+0

請您檢查正確答案?謝謝 – Yoan

回答

43

油滑有一個非常簡單的方法,通過在自己配置兩個變量來定製它的按鈕:prevArrow和nextArrow。

兩種類型都是:string(html | jQuery selector)|對象(DOM節點| jQuery對象),所以在設置光滑滑塊可以設置類:

prevArrow: $('.prev') 
nextArrow: $('.next') 

,並添加這些元素,你想要的風格。

例如:

//HTML 
<div class="slider-box _clearfix"> 
    <div class="slick-slider"> 
     <div> 
      <img src="img/home_carousel/home_carorusel_1.jpg"> 
     </div> 
     <div> 
      <img src="img/home_carousel/home_carorusel_2.jpg"> 
     </div> 
     <div> 
      <img src="img/home_carousel/home_carorusel_3.jpg"> 
     </div> 
     <div> 
      <img src="img/home_carousel/home_carorusel_4.jpg"> 
     </div> 
    </div> 
</div> 

<div class="paginator-center text-color text-center"> 
    <h6>VER MAS LANZAMIENTOS</h6> 
    <ul> 
     <li class="prev"></li> 
     <li class="next"></li> 
    </ul> 
</div> 

//JS 
$(document).ready(function() { 
    $('.slick-slider').slick({ 
     centerMode: true, 
     centerPadding: '60px', 
     slidesToShow: 3, 
     prevArrow: $('.prev'), 
     nextArrow: $('.next'), 
}); 

//CSS 
.paginator{ 
    position: relative; 
    float: right; 
    margin-bottom: 20px; 

    li{ 
    margin-top: 20px; 
    position: relative; 
    float: left; 

    margin-right: 20px; 

    &.prev{ 
     display: block; 
     height: 20px; 
     width: 20px; 
     background: url('../img/back.png') no-repeat;; 
    } 

    &.next{ 
     display: block; 
     height: 20px; 
     width: 20px; 
     background: url('../img/next.png') no-repeat;; 
    } 
    } 
} 
+1

prevArrow:$('.prev') nextArrow:$('.next')。不正確的圓點位置讓我混淆了一分鐘 –

+0

可悲的是,如果在一個頁面上有兩個或多個滑動滑塊,這將不起作用。如果是這種情況,那麼每個自定義的prev/next按鈕都將滑動該頁面上的所有滑塊。如何才能爲該特定滑塊定義「那個」一個DOM元素作爲上一個/下一個按鈕? – Juuro

+0

@Juuro簡單,你只需添加一個更具體的選擇器,而不是僅僅使用''.prev''。 – Sgnl

29

您可以輕鬆地創建自己與.slick-next:before.slick-prev:after僞類箭頭的樣式。

下面是一個例子:

.slick-prev:after { 
    content: ">"; 
    color: red; 
    font-size: 30px; 
} 

.slick-next:before { 
    content: "<"; 
    color: red; 
    font-size: 30px; 
} 
+2

不錯,但不完全正確。應該是:.slick-next:之前{ \t \t內容:「>」; \t \t顏色:紅色; \t \t font-size:30px; \t} \t .slick-prev:before { \t \t content:「<」; \t \t顏色:紅色; \t \t font-size:30px; \t}(使用版本1.6.0) – mhenry1384

+0

對我來說,這不適用於「懸停」效果。它會恢復爲默認大小和內容。我錯過了什麼? –

-1

在你的script.js文件,你可以添加這樣的事情。

jQuery(document).ready(function(){ 
     $('.slick-prev').html('something'); 
     $('.slick-next').html('something') 
}); 
+1

這些按鈕在文檔準備就緒時不會存在,一旦光滑實例被實例化,它們就會被添加。你會想使用slick提供的'init'事件來修改按鈕html。 – Kiee

9

這爲我工作:

http://codepen.io/anon/pen/qNbWwK

隱藏在CSS和使用默認的按鈕:

<!-- In HTML: --> 
<p class="left">left</p> 
<p class="right">right</p> 

/* In the JS file */ 
$('.slider').slick({ 
    arrows: false 
}) 

$('.left').click(function(){ 
    $('.slider').slick('slickPrev'); 
}) 

$('.right').click(function(){ 
    $('.slider').slick('slickNext'); 
}) 
+0

您的解決方案非常完美,謝謝。它應該被標記爲解決方案......無論如何非常感謝 –

4

您可以使用FontAwesome 「內容」 的價值觀,並通過應用如下CSS。這些應用「雪佛龍右/左」圖標。

.custom-slick .slick-prev:before { 
    content: ""; 
    font-family: 'FontAwesome'; 
    font-size: 22px; 
} 
.custom-slick .slick-next:before { 
    content: ""; 
    font-family: 'FontAwesome'; 
    font-size: 22px; 
} 
5

如果您使用的青菜,你可以簡單地設置下面提到的變量,

$slick-font-family:FontAwesome; 
$slick-prev-character: "\f053"; 
$slick-next-character: "\f054"; 

這將改變由光滑的主題CSS中使用的字體系列,也爲上一個和下一個按鈕unicode的。可配置

其他青菜變量Slick Github page

6

它很容易給出。使用波紋管代碼,它適用於我。這裏我使用了fontawesome圖標,但是您可以使用任何圖像或任何其他圖標的代碼。

$(document).ready(function(){ 
     $('.slider').slick({ 
      autoplay:true, 
      arrows: true, 
      prevArrow:"<button type='button' class='slick-prev pull-left'><i class='fa fa-angle-left' aria-hidden='true'></i></button>", 
      nextArrow:"<button type='button' class='slick-next pull-right'><i class='fa fa-angle-right' aria-hidden='true'></i></button>" 
     }); 
    });