Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click to center image function not working in scroll gallery #189

Open
anesca opened this issue Mar 18, 2015 · 1 comment
Open

Click to center image function not working in scroll gallery #189

anesca opened this issue Mar 18, 2015 · 1 comment

Comments

@anesca
Copy link

anesca commented Mar 18, 2015

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
Copy link

DanWebb commented Jan 14, 2016

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants