Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  140] [ 5]  / answers: 1 / hits: 23855  / 9 Years ago, tue, june 23, 2015, 12:00:00

We're using OwlCarousel 1.3.3 on our responsive site. We've set the max number of items to 4.



$container.owlCarousel({
items: 4,
itemsDesktop: [1000, 4],
itemsDesktopSmall: [900, 3],
itemsTablet: [600, 2],
itemsMobile: [480, 1]
});


As long as the carousel contains 4 or more images everything works fine. But when an editor only adds 3 or less items we want those items to be centered on the page. Right now they're left aligned and it doesn't look very good.



The option itemsScaleUp is not what I'm looking for. If items is set to 4 but the carousel only contains 1 item that item would get too big.



I've found these issues on github:

https://github.com/smashingboxes/OwlCarousel2/issues/35

https://github.com/OwlFonk/OwlCarousel/issues/417

But nothing I find helpful.



You can see the issue in this codepen.



Update:

Looking through the source of OwlCarousel you'll see that the .owl-wrapper elements width gets multiplied with 2. But I can't figure out why, and if it's safe to remove the multiplier.



I've opened this github issue to try to get some clarification.


More From » css

 Answers
2

OwlCarousel has a 2x multiplier on the .owl-wrapper elements width. This multiplier makes it incredibly hard to center the carousel when it's less than full.



However, this multiplier doesn't seem to have any reason to be there. Nothing seems to break when I remove it. So that's what I did, the updated owl.carousel.js can be found here: https://github.com/Vinnovera/OwlCarousel/tree/remove-width-multiplier



And I added this CSS (which is not included in the repo):



.owl-wrapper {
margin: 0 auto;
}

[#66086] Sunday, June 21, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maya

Total Points: 418
Total Questions: 116
Total Answers: 112

Location: Mauritania
Member since Sun, Oct 17, 2021
3 Years ago
maya questions
Sun, Jul 4, 21, 00:00, 3 Years ago
Tue, Dec 22, 20, 00:00, 4 Years ago
Fri, Nov 6, 20, 00:00, 4 Years ago
Wed, Jul 29, 20, 00:00, 4 Years ago
Tue, Apr 21, 20, 00:00, 4 Years ago
;