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

Scroll to specific item on responsive carousel #838

Open
daniellelecomte opened this issue Oct 11, 2018 · 2 comments
Open

Scroll to specific item on responsive carousel #838

daniellelecomte opened this issue Oct 11, 2018 · 2 comments

Comments

@daniellelecomte
Copy link

Hey there! Thanks for such a great tool!

Is it possible to set which item displays first on a responsive carousel? I tried adding scroll with no luck...

(function($) {
    $(function() {
        var jcarousel = $('.jcarousel');
        var lIndex = 5;
        jcarousel
            .on('jcarousel:reload jcarousel:create', function () {
              var carousel = $(this),
                  width = carousel.innerWidth();

              if (width >= 900) {
                  width = width / 3;
              } else if (width >= 600) {
                  width = width / 2;
              } else if (width >= 250) {
                  width = width / 1;
              }

              carousel.jcarousel('items').css('width', Math.ceil(width) + 'px');

              console.log("index: " + lIndex);
            })

            .jcarousel({
	            scroll: lIndex
	          });

        $('.jcarousel-control-prev')
            .jcarouselControl({
                target: '-=1'
            });

        $('.jcarousel-control-next')
	        .jcarouselControl({
	            target: '+=1'
	        });
    });
})(jQuery);

We are displaying sports scores and want to set the first item you see to be based upon the time of day by setting a var of 'lIndex' as noted in my code.

This is the staging site for reference:
http://www.thesportsarena.net/staging/public_html/#skatesafescorescroller

Any help would be greatly appreciated. Thanks again!

@snake-345
Copy link
Collaborator

Hello. You can call scroll method without animation after jcarousel initialization.

jcarousel
  .on('jcarousel:reload jcarousel:create', function () {
    ...
  })
  .jcarousel() // initialization
  .jcarousel('scroll', lindex, false); // call scroll without animation for setting initalized slide

@jsor
Copy link
Owner

jsor commented Oct 17, 2018

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

3 participants