12

I am using an OWL Carousel for my slider.

What I am trying to do is slide 2 items when next previous is clicked.

So its sliding to every second item still showing the second item during the transmission.

I have tried to work it out with CSS but no success.

Here is my basic setup

$("#owl-demo").owlCarousel({

  navigation : true, // Show next and prev buttons
  slideSpeed : 600,
  paginationSpeed : 400,
  singleItem:true,

  // "singleItem:true" is a shortcut for:
  // items : 2 
  // itemsDesktop : false,
  // itemsDesktopSmall : false,
  // itemsTablet: false,
  // itemsMobile : false

});

Any help much appreciated.

Thanks in advance.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Dom
  • 3,126
  • 14
  • 46
  • 68

8 Answers8

28

Don't change plugin code, you just need to intialize carousel with slideBy option as mentioned below.

//Initialize Plugin
$(".owl-carousel").owlCarousel(
  {
    slideBy: 4
  }
);
  • Works perfect for me with owl-carousel v2.0.0. This option is also available at the responsive settings. – webster Sep 30 '15 at 13:01
17
scrollPerPage : true

This may help

Andrii Motsyk
  • 439
  • 5
  • 6
8
jQuery(".view-id-frontpage .view-content").owlCarousel( {
  items: 2,
  itemsDesktop : [1000,2], // 2 items between 1000px and 901px
  itemsDesktopSmall : [900,2], // betweem 900px and 601px
  itemsTablet: [700,1], // 2 items between 600 and 480
  itemsMobile : [479,1] , // 1 item between 479 and 0
  navigation: true,
  lazyLoad: true,
  pagination: false,
  scrollPerPage : true
});

This helped me.

Sandeep Kumar M
  • 3,841
  • 3
  • 38
  • 59
Valentina
  • 81
  • 1
  • 1
4

In the current version of Owl Carousel (1.3.2), find the "owl.carousel.js" file and scroll to line #558. The line will read:

base.currentItem += base.options.scrollPerPage === true ? base.options.items : 1;

Change the last number to "2" so that it reads:

base.currentItem += base.options.scrollPerPage === true ? base.options.items : 2;

Save the file, and that should make the slider move by two items.

NinoLopezWeb
  • 151
  • 10
3
Slide 2 items in OWL Carousel

Check this Example

http://jsfiddle.net/k0nn7yw5/107/

Rizwan Akram
  • 220
  • 2
  • 5
3

You can easily add

slideBy: 2

https://owlcarousel2.github.io/OwlCarousel2/docs/api-options.html

Chami M
  • 146
  • 1
  • 7
2

The above answers are helpful but they are incomplete.

Replace Line 558 in owl.carousel.js:

base.currentItem += base.options.scrollPerPage === true ? base.options.items : 2;

Replace line 559 in owl.carousel.js with:

if (base.currentItem > base.maximumItem + (base.options.scrollPerPage === true ? (base.options.items - 1) : 0)) {

This will make the carousel scroll by 2 when you click next but you still need to account for when a user clicks on the prev button. The Following will do just that

Replace line 581 in owl.carousel.js with:

base.currentItem -= base.options.scrollPerPage === true ? base.options.items : 2;

Now you need to account for an odd number of items in your carousel so it will click all the way through every item.

Add this code on line 582 directly under the code in the previous step:

if (base.currentItem === -1) base.currentItem = 0;

I hope this help.

vard
  • 4,057
  • 2
  • 26
  • 46
Ben Callis
  • 21
  • 4
1

For Next button,

//base.currentItem += base.options.scrollPerPage === true ? base.options.items : 1;
To
base.currentItem += base.options.scrollPerPage === true ? base.options.items : 2;

For Previous button,

//base.currentItem -= base.options.scrollPerPage === true ? base.options.items : 1;
To
base.currentItem -= base.options.scrollPerPage === true ? base.options.items : 2;
Kiran
  • 1,176
  • 2
  • 14
  • 27