javascript - Bring image in front of slick carousel - Stack Overflow

I created a carouselslider of images with slick and now I want to increase the size of an image on hov

I created a carousel/slider of images with slick and now I want to increase the size of an image on hover.

When I try to do that the image is cut-off by the slick container. How can I bring the image to front so I can see the whole thing? I tried using z-index but it doesn't work.

JSFiddle of my code. Here's a screenshot with the problematic hover behaviour.

What I want:

I created a carousel/slider of images with slick and now I want to increase the size of an image on hover.

When I try to do that the image is cut-off by the slick container. How can I bring the image to front so I can see the whole thing? I tried using z-index but it doesn't work.

JSFiddle of my code. Here's a screenshot with the problematic hover behaviour.

What I want:

Share Improve this question asked Dec 20, 2016 at 20:04 edoedo 1,8792 gold badges22 silver badges24 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

The problem is that slick adding overflow:hidden to the slick-slider class that contains your images.

you can override this by adding this to your css:

.my-slider > div {
  overflow:visible;
}

EDIT:

my bad, you should do

.my-slider > div {
  overflow-y:visible;
}

so the hidden images will stay hidden.

Overflow being hidden is what's preventing the scaled image from showing entirely. But you can't simply show overflow as this will cause the hidden slides to show.

What you need to do is clone the scaled image outside of the carousel. Here is a working JSFiddle

$(".zoom-it").mouseenter(function(){
    var $this = $(this);
    var position = $this.offset();
    $this.clone()
        .addClass('scaled')
        .insertAfter($(".my-slider"))
        .css({left: position.left, top: position.top});
});

$(document).on('mouseleave', ".zoom-it.scaled", function(){
    $(this).remove();
});

With updated CSS

.zoom-it.scaled {
    transform: scale(2);
    position: absolute;
}

This will clone the hovered image, placing a scaled version on top and removing it when the mouse leaves it.

Another solution that produces the desired functionality is to add padding to the div wrapper slick adds to your outermost carousel container. Just fixed this after hours of struggling with it. Hope this helps someone.

.carousel-class-name > div { padding: 20px 0px 20px 0px }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745426273a4627191.html

相关推荐

  • javascript - Bring image in front of slick carousel - Stack Overflow

    I created a carouselslider of images with slick and now I want to increase the size of an image on hov

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信