Add custom buttons on Slick Carousel

前端 未结 11 669
迷失自我
迷失自我 2020-12-23 14:23

How do I apply custom prev and next buttons to slick carousel? I have tried a background image on the .slick-prev and .slick-next css classes. I ha

11条回答
  •  北海茫月
    2020-12-23 15:07

    A variation on the answer by @tallgirltaadaa , draw your own button in the shape of a caret:

    var a = $('.MyCarouselContainer').slick({
        prevArrow: '',
        nextArrow: ''
    });
    
    function drawNextPreviousArrows(strokeColor) {
        var c = $(".prevArrowCanvas")[0];
        var ctx = c.getContext("2d");
        ctx.clearRect(0, 0, c.width, c.height);
        ctx.moveTo(15, 0);
        ctx.lineTo(0, 25);
        ctx.lineTo(15, 50);
        ctx.lineWidth = 2;
        ctx.strokeStyle = strokeColor;
        ctx.stroke();
        var c = $(".nextArrowCanvas")[0];
        var ctx = c.getContext("2d");
        ctx.clearRect(0, 0, c.width, c.height);
        ctx.moveTo(0, 0);
        ctx.lineTo(15, 25);
        ctx.lineTo(0, 50);
        ctx.lineWidth = 2;
        ctx.strokeStyle = strokeColor;
        ctx.stroke();
    }
    drawNextPreviousArrows("#cccccc");
    

    then add the css

    .slick-prev, .slick-next 
        height: 50px;s
    }
    

提交回复
热议问题