Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick Slider slickGoTo method breaking the carousel

I'm working on a news article page that also has a gallery of images. I'm using slick slider for the thumbnails on the gallery. Every image in the gallery has it's own url for ad view purposes (not nice but nothing I can do about it) like our-url.com/category/articlewithgallery/1, 2 or 3 etc...

I'm using responsive breakpoints like this:

$('.gallery-thumbs').slick({
  slidesToShow: 5, slidesToScroll: 5, dots: false, infinite: false, speed: 300,
  responsive: [ { breakpoint: 1024, settings: { slidesToShow: 5, slidesToScroll: 5 } },
  { breakpoint: 600, settings: { slidesToShow: 4, slidesToScroll: 4 } },
  { breakpoint: 438, settings: { slidesToShow: 3, slidesToScroll: 3 } },
  { breakpoint: 270, settings: { slidesToShow: 2, slidesToScroll: 2 } } ]
} );

and this is working fine. But because we have many urls, I'd like the thumbnails to start on the current loaded image. I can accomplish this by adding this:

$('.gallery-thumbs').slickGoTo(parseInt(cur_pic));

The thumbnails start at the correct location, but it breaks the carousel. For example I cant scroll it backwards at all anymore. I can drag and see that there are more thumbnails in that direction but it just bounces back to the (new) starting location. Also if we are on the last "slides", it either doesn't show them at all, or adds empty space after all the thumbnails.

I thought that maybe it's because I don't use the slick sliders "onInit" function and it messes it up because we tell it to go to this slide before initialization or something. I've tried all kinds of stuff and couldn't get any onInit: function() stuff to work.

Could be because I'm quite bad at javascript.

like image 702
jimihenrik Avatar asked Jul 22 '14 14:07

jimihenrik


People also ask

Why is the slick carousel wrapped inside a class?

The slick carousel is wrapped inside a class to provide max-width to the slider. In upcoming sections, we will discuss how to make the slick carousel responsive.

How to show a slide directly using slickgoto method?

The slickGoTo method is used to directly show a slide. Open the app.component.ts file and update it with the following code. Next, add the following style in the styles.scss file to align it properly and color the Next, Prev icons on while background.

Can I use slickgoto&setPosition inside a condition?

Both slickGoTo & setPosition don't respond when I put them in inside a condition. I can set goto just fine when adding it to a click event, like a button goes to slide 4 for instance. But like if I am looking for something like what the last URL was and then I want to position to slide 3 instead of slide 0 on page load, i get nothing.

How to turn off draggable behaviour of slick carouse?

You can turn off the default draggable behaviour of Slick Carouse by setting the draggable:false. The fade effect to slider can be added by using following two props. { ... fade: true, cssEase: 'linear' ...


3 Answers

Its is working. code: $('.firstDiv').slickGoTo(4);

Please see below example

http://jsfiddle.net/9fnmegqb/

And as of version 1.4+ : $('.firstDiv').slick('slickGoTo', 4)

like image 152
Praveen G Avatar answered Sep 22 '22 14:09

Praveen G


As of version 1.4, the methods to invoke actions have changed.

The equivalent code line for the slickGoTo() function is $('#slider_selector_id').slick('slickGoTo', slide_number);

(where #slick_selector_id is the id for the slider, and slide_number is an integer of the slide index required)

(answer from comment as suggested by Alexandre Bourlier in response to the another answer here)

like image 21
Simon Shirley Avatar answered Sep 22 '22 14:09

Simon Shirley


The solution that I have found working is to change the infinite to true

$('.gallery-thumbs').slick({
  slidesToShow: 5, slidesToScroll: 5, dots: false, infinite: true, speed: 300, responsive: 
  [ 
    { breakpoint: 1024, settings: { slidesToShow: 5, slidesToScroll: 5 } },
    { breakpoint: 600, settings: { slidesToShow: 4, slidesToScroll: 4 } },
    { breakpoint: 438, settings: { slidesToShow: 3, slidesToScroll: 3 } },
    { breakpoint: 270, settings: { slidesToShow: 2, slidesToScroll: 2 } } 
  ] 
});

I know that the post is 3 years old, but I had to post a workaround solution.

like image 37
gmetax Avatar answered Sep 21 '22 14:09

gmetax