Click to center image function not working in scroll gallery
Opened this issue · 1 comments
anesca commented
First of all, this is a wonderful horizontal scroll gallery and it works beautifully!
I am trying to implement a function where if you click on an image it will bring it to the horizontal center of the scrolling gallery, however it is not working for some reason. I would like to know whether this is because of how the gallery has been coded that it will not allow for this kind of functionality? From what I have been seeing I think it might be the case.
Thanks!
DanWebb commented
I had the same issue, the scrollToElement method works but doesn't align the slide horizontally center. I used the code I've included below to achieve this instead, hopefully it helps.
/**
* Horizontally center a slide
* Example usage: `scrollToSlide($('#Scroller'), $('#slide-1'));`
* @param {object} $scroller - element .smoothDivScroll() was used on
* @param {object} $slide - id of element to scroll to
*/
function scrollToSlide($scroller, $slide) {
var slideLeft = $slide.offset().left;
var slideCenter = $slide.outerWidth()/2;
var scrollerCenter = $scroller.outerWidth()/2;
$scroller.smoothDivScroll("move", (slideCenter+slideLeft)-scrollerCenter);
}